-
Notifications
You must be signed in to change notification settings - Fork 230
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
renderHook (and rerender) doesn't properly infer overload type when using initialProps. #822
Comments
Also, render result does not update its type definition based on the |
We faced this issue even on the latest version (8.0.1), any idea? |
Salutations ! I think you doesn't use const { rerender } = renderHook((nextProps) => useMyHook(nextProps || initialProps))
rerender(myNextProps) This solution work for me 👍 I think renderHook is not well designed to easily understand it and can be a good thing if in the future it can work like that : const { render } = renderHook(useMyHook);
render(initialProps);
render(myNextProps); |
Sorry I'm a bit late to the party here. I believe this is a known limitation of generic type inference of overloaded functions in Typescript. |
@react-testing-library/react
version (if applicable): 12.1.2@react-testing-library/react-hooks
version: 7.0.2react
version: 15.4.2react-dom
version (if applicable): 15.4.2node
version:npm
(oryarn
) version:Relevant code or config:
What you did:
I have a react hook, that relies on overloading to solve different use-cases. Essentially, this hook has an overload that determines the appropriate way to resolve a value based on its parameter
typeof
.What happened:
When faced with an overloadable hook,
@react-testing-library/react-hooks
isn't appropriately typing either theinitialProps
for therenderHook
method, or thererender
method itself.Reproduction:
Reproduction
Problem description:
Hook overloading only works when you explicitly call the hook and return it's value on the
renderHook
method, while when using therenderHook
with theinitialValue
option, it doesn't properly generate the types to match the overload.The text was updated successfully, but these errors were encountered: