reactjs - Call componentWillReceiveProps() after state is getting updated from reducer React/Redux -
i have 2 components
1] parent
2] child
i passing parent components action child called on change of dropdown list.
parent components method calling stores's function (ajax call) , updating state variable. after updating state want perform few operations in componentwillreceiveprops() not going inside componentwillreceiveprops ().
below code in parent component -
1 ] parent
componentwillreceiveprops(props) { this._settracktoparams(props) debugger; let livevideolist = this.state.livevideolist if(props.liveracevideos != null && _.isempty(this.state.livevideolist)) { console.log('live race video if') this.state.livevideolist.push(props.liveracevideos) this.setstate(this.state) } else if(props.liveracevideos != null && this.selectedkey) { console.log('live race video else') this.state.livevideolist[this.selectedkey] = props.liveracevideos this.setstate(this.state) } console.log("bye") } renderchild() { let selectvalue = !this.selectedkey ? this.props.params.trackcode : this.selectedkey if(this.state.livevideolist) { return _.map(this.state.livevideolist,(value , key) => { if(key < 3) { return ( <livevideopanel ref = "livevideopanel" key = {key} currenttracks = {this.props.currenttracks} livevideos = {value} selectedvalue = {selectvalue} onchange = {this._togglevideos} onchangetracklist = {this.onchangetracklist.bind(this)} videocount = {key}/> ) } }) } } onchangetracklist(id, key) { if(id) { this.selectkey = key this.props.fetchliveracevideo(id) } }
so calling this.onchangetracklist() function on change of dropdown list. , function internally calling this.props.fetchliveracevideo(id) action. getting "link" ajax call. , link getting updated in state.
after state updation want call componentwillreceiveprops() , not getting called.
it possible componentwillreceiveprops isn't being called because componentwillmount being called instead. put in console.log , see if case.
from docs:
react doesn't call componentwillreceiveprops initial props during mounting. calls method if of component's props may update. calling this.setstate doesn't trigger componentwillreceiveprops.
Comments
Post a Comment