Is it bad practice to use state components without going through the reduction?

Let's say I don't want my checkboxes to show up in the global shortcut store. Because I don't want to deal with actions and reducers for this small local state. So I want to use explicitly setState()

inside my component.

Is it bad practice (for example in the testing aspect)?

+3


source to share


2 answers


In the Redux FAQ entry about component state and Redux state :



Using local component state is fine. As a developer, your job is to determine which state your application is made up of and where each state should live. Find a balance that works for you and go with it.

Some general rules for determining what data should be put into Redux:

  • Do other parts of the application leave this data?
  • Do you need to be able to create additional derived data based on this raw data?
  • Is the same data used to control multiple components?
  • Do you have value in restoring this state to a given point in time (i.e. debugging in time)?
  • Do you want to cache the data (i.e. use what's in the state if it already exists instead of re-requesting it)?
+3


source


It is perfectly okay to keep the state of a checkbox in a local state if it is data independent.



It is good practice to store all of your data in your redux store and ui-related state in your local store.

+3


source







All Articles