Dealing with local state in react and redux

后端 未结 3 1961
时光说笑
时光说笑 2021-02-02 10:01

Is it OK to store local state in the state object when using react together with redux? Storing everything in the state tree via actions quickly becomes tedious. It

3条回答
  •  灰色年华
    2021-02-02 10:41

    This is difficult to answer, because different people will classify different parts of a component as "state".

    Since Redux is concerned with application state, as a rule of thumb, anything you would expect an application level "undo/redo" button to effect should happen as a Redux Action. The fact that Redux has an undo store plugin is possible only because of the reach of application state.

    Certainly some animations would not be undoable, since these should really be connected to changes in the app state, not changes in-and-of themselves. The rest of your examples, though, sound very much like app state. If I sorted a table, and then pressed undo, I would absolutely expect the sorting to be undone.

提交回复
热议问题