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
useNavigateinternally.Understandably,
useNavigaterelies 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.createRemixStubseemed like a potentially promising way to wrap our entire storybook in a<RemixStub>element to create those contexts, butRemixStubdoesn't take achildrenprop.A lot of the time it's possible to keep
useNavigateout of our reusable components, but in some we're using React Aria'sRouterProviderwhich requires the router'snavigatefunction.As a workaround, we're using a
useNavigateSafewrapper which wrapsuseNavigatein atry-catchand 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/testingpackage exported something that would create a dummy/memory router, which would allow people to useuseNavigateoutside of Remix.We also run into the same kind of problem with
useLocationanduseParamsand 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