lundi 7 septembre 2020

Persisting redux state vs dynamic urls

In the app I am working on I have a state that is chosen in a dropdown by the user. I would like this state to still be the same after the user refreshes the page

Two options:

  1. Store the state in the url by adding "/:state"
  • We must hit the api endpoint again to get the data based on the state. So it is always fresh
  • The url can be stored in history and copied/bookmarked
  • Everytime the state is changed by the user, the url changes causing a reload of the page
  1. Store the state in redux and persist it
  • Have to install a package like redux-persist which takes some configuration
  • data persists on page reload so we don't need another api call
  • data may be outdated and need to be re-pulled

Which option is better? What scenarios break either option?




Aucun commentaire:

Enregistrer un commentaire