Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref Type incorrect #110

Closed
lachieh opened this issue Jan 3, 2024 · 3 comments · Fixed by #111
Closed

ref Type incorrect #110

lachieh opened this issue Jan 3, 2024 · 3 comments · Fixed by #111

Comments

@lachieh
Copy link
Contributor

lachieh commented Jan 3, 2024

Currently the type of the ref prop on the Player component is inherited from the HTMLDivElement, but in the source the Lottie instance is passed to the forwarded ref.

Type inheriting here:

export type LottieProps = React.DetailedHTMLProps<
React.HTMLAttributes<HTMLDivElement>,
HTMLDivElement
> &
Partial<Pick<AnimationConfig<RendererType>, 'loop' | 'renderer' | 'rendererSettings' | 'audioFactory'>> & {
play?: boolean
goTo?: number
speed?: number
direction?: AnimationDirection
segments?: AnimationSegment | AnimationSegment[]
useSubframes?: boolean
onComplete?: AnimationEventCallback
onLoopComplete?: AnimationEventCallback
onEnterFrame?: AnimationEventCallback
onSegmentStart?: AnimationEventCallback
} & ({ path?: string } | { animationData?: object })

Lottie ref assigned here:

const setLottieRefs = useCallback((newRef) => {
animRef.current = newRef;
// eslint-disable-next-line no-param-reassign
if (forwardedRef) forwardedRef.current = newRef;
}, []); // eslint-disable-line react-hooks/exhaustive-deps

I am happy to assist with correcting this by exposing the animElementRef prop and correcting the types for both if a PR would be accepted.

@mifi
Copy link
Owner

mifi commented Jan 4, 2024

pr is welcome!

@mifi
Copy link
Owner

mifi commented Jan 4, 2024

although im not sure why nobody has hit this issue before

@lachieh
Copy link
Contributor Author

lachieh commented Jan 4, 2024

Thanks, I'll get to that over the next couple of days.

although im not sure why nobody has hit this issue before

My guess is that you've covered the 80% use case by accepting various props, and I'm operating in the 20% use case because I need control over the Lottie instance. Multiply that with typescript usage and it's likely a pretty small number of people who have hit this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants