Skip to content

Form field content isn't updating #1797

Closed Answered by sergiodxa
bmaupin asked this question in Q&A
Discussion options

You must be logged in to vote

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.

let { initialValue } = useLoaderData()
let location = useLocation()
return <input key={location.key} name="something" defaultValue={initialValue} />

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.

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by bmaupin
Comment options

You must be logged in to vote
1 reply
@sergiodxa
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants