Skip to content

Why is result a ref(-like)? #3

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

Closed
BigAB opened this issue Feb 21, 2019 · 1 comment
Closed

Why is result a ref(-like)? #3

BigAB opened this issue Feb 21, 2019 · 1 comment

Comments

@BigAB
Copy link

BigAB commented Feb 21, 2019

Is there a reason why result is a Ref (or ref-like)?

What is the advantage of getting the result off result.current instead of the direct result?

const { result } = renderHook(() => useTheme('light'))
const theme = result.current
// why not...?
const { result: theme } = renderHook(() => useTheme('light'))

It would be a very simple change
https://github.com/mpeyper/react-hooks-testing-library/blob/master/src/index.js#L24

So, I feel like I must be missing something obvious.

@BigAB
Copy link
Author

BigAB commented Feb 21, 2019

Oh I see the value in it now.

When you are re-rendering, either through state change or calling rerender() the value returned by the hook may be different, but your test isn't going to re-run. You make assertions on the last value you got though by checking result.current

Thanks,

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

No branches or pull requests

1 participant