Best way to persist data across routes? #4267
Replies: 3 comments 16 replies
-
As with most tech decisions, it depends. If the data needs to be persisted for long term, then store the data in a database and fetch from each loader. If the data is tied to a specific user and is only needed for the duration of the session, then use session storage. If the session data is small, then you can use cookies. Otherwise use an external session store. If you're using cookie sessions, remember all the session data is stored in the cookie. Mutating the session in one loader does not guarantee the other loader will see it, since it will need to have made the round trip from the browser. That is why it's recommended you only mutate session from your action, since there is only one action running at a time. If you want to save user preferences across sessions, either store in database or a persistent cookie. If the data is dynamic and useful for all users, then use a cache like Redis or lru-cache. Generally it's ok to refetch data across loaders. Since loaders run in parallel, and conceivably across different processes, you can't really share data (except with a cache). And remember, most databases also has a cache, so the same query executed multiple times will return from db cache instead of reprocessed. I would do the simplest way first, then measure with expected load, and refine appropriately. |
Beta Was this translation helpful? Give feedback.
-
I am trying to create a countdown in my remix app that is also persistent across page reloads. Using |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
What's the consensus on persisting data across different routes?
I have a form on route
/foo
and another one on page/bar
that uses some info from/foo
.Is session storage (particularly
createSession()
) the way to go for my use case? Should I useglobal
instead?I have seen similar questions in here without an answer, so I don't seem to be the only one puzzled by this.
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions