Dealing with local state in react and redux

后端 未结 3 1996
时光说笑
时光说笑 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:59

    This is now answered in the redux FAQs:

    There is no “right” answer for this. Some users prefer to keep every single piece of data in Redux, to maintain a fully serializable and controlled version of their application at all times. Others prefer to keep non-critical or UI state, such as “is this dropdown currently open”, inside a component's internal 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.

提交回复
热议问题