React redux state management issu

recently encountered a confusion as follows:

suppose I get a list of original items by request, and I store it in store

state = {
    products:[...]
}

in a component, users can hide items they don"t care about (ps: is not deleted, similar to adding a show:false attribute). I thought of several ways myself:

1. Add a show attribute to each item in products directly.
II. Create another backup of products in store productsCopy , and then add the show attribute.
3. Save a copy of the products to the private state of this component.

the problem is:
1. In method 1, when more and more fields are added, there will be a lot of initialization work to be done after requesting the products interface.
2. For the state that other components don"t care about, I don"t think it"s a good choice to put it in redux store, and I need to write action, reducer, constant, write all kinds of import, etc., a lot of code.
3. Method 3 needs to listen for changes in products in componentWillReceiveProps, and then transfer Synchronize to private state. It feels a bit troublesome, and it"s not easy to tell the difference between props.products changes and other props changes.

how do you usually deal with it? Is there a better solution?


only one copy of the data is saved, just add fields. Also, you don't need to use the redux, componentWillReceiveProps method.

what I do is to manipulate only this piece of data. Add show: false to the data that you don't need to display. Just fine.


I will choose the first one and add a show attribute to the products item in store. Then, when mapStateToProps, do select (maybe use the reselect library to cache select) and filter out the products.
whose show is true. Why not save a copy in the private state of this component?
because I think:

  1. changing state, through props is anti-pattern, which violates a single data source and complicates data flow
  2. is stored in state, and when the component is destroyed, the values in state are also destroyed. After the user hides the products, exits the current component and enters the component again, there should be no hope that the hidden products will be displayed again. So it is still necessary to store product show or hide, at the application level.
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b2aea8-2ba6a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b2aea8-2ba6a.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?