Skip to content

Commit 951208f

Browse files
authored
fix: correct types for useSynchronizedAnimation (#16)
If we don't default to null it is not usable with styled-components. Also add template types similar to useRef.
1 parent d42629d commit 951208f

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/useSynchronizedAnimation.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import { useLayoutEffect, useRef } from 'react'
22

3-
export const useSynchronizedAnimation = (options?: GetAnimationsOptions) => {
4-
const ref = useRef<HTMLElement>()
3+
export const useSynchronizedAnimation = <E extends HTMLElement>(
4+
options?: GetAnimationsOptions
5+
) => {
6+
const ref = useRef<E | null>(null)
57
useLayoutEffect(() => {
8+
const currentTime = document.timeline?.currentTime ?? 0
69
ref.current
710
?.getAnimations(options)
8-
.forEach(a => (a.currentTime = document.timeline.currentTime))
11+
.forEach(a => (a.currentTime = currentTime))
912
}, [options])
1013
return ref
1114
}

0 commit comments

Comments
 (0)