I would like to know why the function gets called multiple times wheh dispatch. Also, is there any better way to do,
getData = (value) =>{
const body = {
value: value,
cn: "TH"
}
return body;
}
renderData(){
console.log("starts");
this.props.dispatch(queryData(this.getData(10)));// called repeatedly
}
render(){
return(
<div>{this.renderData()}</div>
)
}
I have updated the different scenario by same type, I need to know is there any other better way to.
scenario 2
getData = () =>{
const body = {
value: value,
cn: "TH"
}
return body;
}
componentDidMount=()=>{
this.props.dispatch(queryData(this.getData()))
}
componentDidUpdate = () => {
const {allstate} = this.props.querydata
if(this.props.querydata){
this.renderState(allstate);
}
}
renderState = (data) => {
const getId = data.map(e=>e.id); //will get array of values [2, 3, 4]
getid.map(e=>
this.props.dispatch(queryState(e))); //for every id dispatch props,
)
}
render(){
// will gets this by componentDidMount call
return (
<div>
</div>
)
}