Replies: 1 comment
-
This is what we did that allowed putting MyComponent (which uses useNavigate) in Storybook
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We develop most of our components as stories (using ladle.dev) and we're running into problems with any component that uses
useNavigate
internally.Understandably,
useNavigate
relies on there being some routing context available from Remix, but when that context isn't there (such as inside a story) the whole component blows up.createRemixStub
seemed like a potentially promising way to wrap our entire storybook in a<RemixStub>
element to create those contexts, butRemixStub
doesn't take achildren
prop.A lot of the time it's possible to keep
useNavigate
out of our reusable components, but in some we're using React Aria'sRouterProvider
which requires the router'snavigate
function.As a workaround, we're using a
useNavigateSafe
wrapper which wrapsuseNavigate
in atry-catch
and gives back a no-op function when the context isn't there.This works fine, but it feels like an unreasonably hacky workaround for a relatively common problem.
It would be great if the
@remix-run/testing
package exported something that would create a dummy/memory router, which would allow people to useuseNavigate
outside of Remix.We also run into the same kind of problem with
useLocation
anduseParams
and having a way to set the params as part of the stub/router provider would be very helpful.Beta Was this translation helpful? Give feedback.
All reactions