Skip to content

useState always using initial value on route change #131

Answered by tannerlinsley
DPCamino asked this question in Q&A
Discussion options

You must be logged in to vote

Sorry, I think we misunderstood each other. In your example, the useState is being unmounted as you transition to the individual post view. It's not rendered any more, so it's memory is thrown away. This is how React works at a fundamental level. You are 100% correct that you cannot persist component state without some type of external storage (global store, server store, URL store).

Sorry it took me a bit to figure out what you were referring to.

Replies: 3 comments 4 replies

Comment options

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

Comment options

You must be logged in to vote
0 replies
Comment options

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

@DPCamino
Comment options

@tannerlinsley
Comment options

Answer selected by tannerlinsley
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