Skip to content
Discussion options

You must be logged in to vote

This is how state works in React, once a component is mounted and a state is initialized if the value used as the default for the state changes React will not sync it again.

You have a few options:

  1. Use loaderData.posts directly without a state, if you never change the state why use one?
  2. Add an useEffect that runs when the loader data changes and sets the state to the loader data
  3. Create a second component which holds the state and renders the UI, then in the route component add a key={location.key} props (you get the location from Remix's useLocation hook) so every time there's a location change (e.g. when search params change) it will re-mount the component initializing the state again (…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@kicut
Comment options

@juniorforlife
Comment options

@lambdaxyzt
Comment options

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