How to update state in class component

Viewed 22

I map product fetch from store/redux and after action I want update the state of nested component.

It all looks cool in store - action -> dispatcher -> reducer works perfect (in another - third component state is changed), but in nested component I map attributes and have function that selectedAttributes checked. At first render it looks pretty cool. But after I click another input the check does not appear but still there is. And new check is also. And if I click another one, all inputs I checked, still are checked. In store is cool, and display the last action, but the user experience is not so cool.

I think how to use here Observator pattern. I tried in parent component (which mapsProps) componentDidUpdate(){ this.forceUpdate() } because I want it after action, render component. But there is an error infinite loop.

Update:

I read that I just need to change something into reducer.

my reducer:

 ...product,
     ...product.selectedAttributes.map(p =>{
                
                if(p.name === name){p.value = value}
            })

I tried add here an array but this noting to change.

0 Answers
Related