Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should you store Application state in local state or Redux Store

Tags:

reactjs

redux

I have been working with Redux for almost a month now. My question is this that I am putting all my app data in the redux store, but should I also put the toggle states that helps me change my UI in redux state or should I simply manage that locally in each page by just doing

this.setState({ showActiveForm : false })

like image 386
Adeel Imran Avatar asked Mar 06 '17 08:03

Adeel Imran


1 Answers

There is no right or wrong answer for this. To help you decide, here are some common rules of thumb taken directly from the redux documentation:

  • Do other parts of the application care about this data?
  • Do you need to be able to create further derived data based on this original data?
  • Is the same data being used to drive multiple components?
  • Is there value to you in being able to restore this state to a given point in time (ie, time travel debugging)?
  • Do you want to cache the data (ie, use what's in state if it's already there instead of re-requesting it)?

Another advantage to keeping the majority of your UI state in redux is that you can write more stateless functional components and make use of the performance optimisations they will bring in future versions of React:

This pattern is designed to encourage the creation of these simple components that should comprise large portions of your apps. In the future, we’ll also be able to make performance optimizations specific to these components by avoiding unnecessary checks and memory allocations.

like image 68
Paul. B Avatar answered Oct 21 '22 05:10

Paul. B