Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it anti-pattern to use Component state in Redux? [duplicate]

I currently have my store setup. Various things trigger events to update the store, which updates props downstream. This is really handy when triggering something to make updates in multiple components.

Is it anti-pattern to use state for things no other components care about?

I basically have a component that is a page of a form. Editing the form updates state (ie selecting one option makes other options change). I figure when the user hits save, I will trigger event for store to have the new data. Hitting cancel would just go back to another page so returning later will just repopulate from store state.

Does that make sense?

like image 585
Dave Stein Avatar asked Dec 24 '22 06:12

Dave Stein


1 Answers

Using internal state is perfectly fine (and encouraged!) in simple behavior like what you describe. Things like the state of a modal (open/close), checkboxes, and other minor things like that are perfectly fine contained within React state.

Remember that Redux is most useful in handling global app state. When trying to decide where to keep state, try answering the question "Will any other part of the app care at all about a change to this?" If so, use the Redux store. Otherwise, go ahead with internal state.

like image 81
ZekeDroid Avatar answered Dec 28 '22 14:12

ZekeDroid