I have ParentComponent
render(){
return('<'Child1Component/> '<'Child2Component/>)
}
So, I'm in Child2Component how to change State in Child1Componet with parameter. It is possible?
You can call one method of parent from child1 , and this method will call another method of child2 using refs
add this to your parent component
onPressSuccess = params => {
this.refs.ComponentTwo.componentTwoMethod(params);
};
render() {
return (
<View>
<ComponentOne onPressSuccess={this.onPressSuccess}> ... </ComponentOne>
<ComponentTwo ref={"ComponentTwo"}> ... </ComponentTwo>
</View>
);
}
In <ComponentOne>
call this.props.onPressSuccess(params)
where params
is parameters you want pass along with method.
here componentTwoMethod
is a method in <ComponentTwo>
, which can take params and set state or whatever you want to do.