Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it a bad practice to use stateful components bypassing redux?

Say, I don't want to keep my checkboxes state in global redux store. Cause I don't want to deal with actions and reducers for this small local state. So I want to explicitly use setState() inside my component.

Is it a bad practice (for instance, in testing aspect)?

like image 794
GProst Avatar asked Mar 09 '23 06:03

GProst


2 Answers

Per the Redux FAQ entry on component state vs Redux state:

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

Some common rules of thumb for determing what kind of data should be put into Redux:

  • 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)?
like image 198
markerikson Avatar answered Mar 11 '23 19:03

markerikson


It's absolutely fine to keep the checkbox state in you local state as long as it doesn't depend on the data.

A good practise is to keep all you data in your redux store and the ui-related state in you local store.

like image 40
Shubham Khatri Avatar answered Mar 11 '23 19:03

Shubham Khatri