I created a Checklist component in which all checks are by default FALSE
, as I click to check any of one I set Component State and send State to the Store reducer
. And After doing so the problem arrives. The problem is that:- I want Store data in another Component(MyComp
) with the help of mapStateToProps
. But componentWillReceiveProps
is not triggered as I changed Checklist data.
I searched for this problem and found that React is not able to Deep checks the upcoming props. I tried with single toggle(true/false)
props and it works for me.
This is MyComp.js which is using Store State(toggle, platforms) as a props
class MyComp extends React.Component{
componentWillReceiveProps=(nextProps)=>{
console.log(nextProps);
// this function is running only when the toggle is changing but not running when I change CheckList State.
}
render()(<div></div>);
}
const mapStateToProps = (State) => {
return {
platforms:State.configuration.platforms!==undefined?State.configuration.platforms:[],//<-- Not triggered componentWillReceiveProps
toggle:State.toggle //<-- it triggered componentWillReceiveProps
}
}
export default connect(mapStateToProps)(FeatureEvents);
...
This is props which are coming from the Store. In this only selected property is changing.
platforms props : [
{
background: "https:image/file/59fd566788f3ac79a46ef20d/Android.png",
description: "Operating system used by various brands",
icon: "https://duj87royd3ze0.cloudfront.net/uploads/image/android.png",
id: "587f1e2f14c49f4aeb4d79d4",
price_multiplier: 1.5,
selected: true,
title: "Android",
week_multiplier: 1.1,
},
{..},
...
{..}
]
EXPECTED: As I changed "selected" property value (true/false) by checked or unchecked in the CheckList, I want to trigger componentWillReceiveProps in MyComp.
CURRENT STATUS: React not Triggering componentWillReceiveProps. Because React is not able to identify deep check.
How can I code so that React will start to deep check upcoming props?