score:1

Accepted answer

you can dipatch the api call this.props.fetchdata(...) in the parent. then update this.state.activecolor in parent. now pass that value as props to child1 or child2.

inside your child components, since you're dispatching the action in componentwillmount, there won't happen a new api call in them when you supply new props from parent.

if you want to update internal states (if any) of the child components upon receiving the new props, you may use componentwillreceiveprops(nextprops).


update:

child1 and child2 receives new color from parent via props. so if you want to trigger the api call on receiving new props, dispatch this.props.fetchdata(...) inside componentwillreceiveprops of child components.

hope you are using es6 classes:

componentwillreceiveprops(nextprops) {
    if (this.props.colorvalue !== nextprops.colorvalue) {
        this.props.fetchdata(this.props.somename, nextprops.colorvalue);
    }
}

also i am assuming you have mapped the action creator fetchdata as props to your child components using connect.


Related Query

More Query from same tag