useHistory in react-router-dom v5
zhex900 opened this issue · 2 comments
What is your question:
I want to use useHistory
hook in my test.
const {result} = renderHook(() => useHistory(), {
wrapper: BrowserRouter,
})
The problem is the result
is got giving me the correct route. It seems like the mounted App
and the useHistory
hook in the test are using two different instances of BrowserRouter
I want to reference useHistory
hook inside the test. So I can know the current path and change routes.
You'll need to share some more code and/or clarify what are are try to do. It sounds like you want to render App
(presumably using react-testing-library
then use renderHook
to read the value of useHistory
from the other render.
If that is the case then I'm sorry, but that is not what this library is for. renderHook
renders the hook inside its own react tree so that you can test the hook in isolation of the component code. We do not share context or rendered component values with any other react tree by design (and I'm not sure it's technically possible either).
Thank you.