简体   繁体   中英

Multiple Instances of the Same Component in React-Redux

How can I have multiple instances of the same container component in React-Redux? Even if I send unique data then also each of the component gets the data of the last component only as the Store is updated using that values. eg -

<ContainerInstance1 data={data1}/>
<ContainerInstance2 data={data2}/>

Container Instance 1 will get the data from the store that is modified by Container Instance 2 while rendering. How to use so that it can get the data correctly?

It sounds like you have some issues, possibly in your reducer - most likely data1 and data2 are in fact the same object.

Make sure you are not mutating state, but instead returning a new state object from your reducers.

If the two data objects above are truely not the same data object - there is no reason why the above shouldn't work as you think it should. In other words, there isn't an issue with the code above, but rather somewhere else.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM