-
I'm completely new to Remix. I'm following the blog tutorial and trying to do the "homework" portion at the end, which is to create an edit page for the posts, which I've done here: https://github.com/bmaupin/remix-test/blob/main/app/routes/admin/%24slug.tsx It works, but I'm seeing weird behaviour:
You can see it for yourself here: https://bmaupin-remix-test.herokuapp.com/admin I tested in Chrome and Firefox with two different hosting providers, and I see the same behaviour when I'm running it locally. My guess is I've done something wrong but I'm not sure what. Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The problem is you are using defaultValue to set the values from the loader, but because the transition happens with JS React is ignoring changes in those values, what you can do is to use the useLocation to get the let { initialValue } = useLoaderData()
let location = useLocation()
return <input key={location.key} name="something" defaultValue={initialValue} /> That way, after a route transition the You can put the key in the Form to force a re-mount of everything. |
Beta Was this translation helpful? Give feedback.
-
@sergiodxa I'm guessing you meant this? There doesn't seem to be a key property on the transition. const location = useLocation();
return <input key={location.key} name="something" defaultValue={initialValue} /> That's what I did (well, I did it on the whole Form because I'm being lazy: bmaupin/remix-test@185b6bf) and it worked. Thanks so much! |
Beta Was this translation helpful? Give feedback.
The problem is you are using defaultValue to set the values from the loader, but because the transition happens with JS React is ignoring changes in those values, what you can do is to use the useLocation to get the
location.key
and force a re-mount of the inputs after a navigation.That way, after a route transition the
location.key
will change and React will re-mount the input using the new defaultValue.You can put the key in the Form to force a re-mount of everything.