React-Redux: Should all component states be kept in Redux Store

后端 未结 4 1895
无人共我
无人共我 2020-12-04 06:39

Say I have a simple toggle:

When I click the button, the Color component changes between red and blue

I might achieve this result by doing somethin

4条回答
  •  执笔经年
    2020-12-04 07:15

    Redux FAQ: Organizing State
    this part of redux official doc well answered your question.

    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 determining 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)?

提交回复
热议问题