Моя панель инструментов уже отображена, и теперь я хочу вызвать компонент componentWillUpdate() на этой панели инструментов, когда мне нужно обновить его состояние?Как вызвать componentWillUpdate() для обновления состояния дочерних компонентов?
HomeScreen
constructor(){
super();
this.state = {
pagenum: 0,
toptoolbartitle: "default",
homeviewtitle: "default",
};
}
updateHomeViewTitle(viewtitle){
console.log(viewtitle);
this.state.homeviewtitle = viewtitle;
console.log("homeviewtitle is now"+this.state.homeviewtitle);
}
render() {
return (
<View style={styles.container}>
<View style={{flex:1}}>
<TopToolbarAndroid
defaulttitle={"default"} titleupdate={this.state.homeviewtitle}/>
<RNCamera updateviewtitle={this.updateHomeViewTitle.bind(this)} />
<BottomBar />
</View>
</View>
TopToolbarAndroid
constructor(props){
super();
this.props = props;
this.state = {
pagenum: 0,
title: this.props.defaulttitle
};
}
componentWillUpdate(){
console.log("component will update?");
if (this.props.titleupdate != null)
{console.log("updating toolbar title to: "+this.props.titleupdate);
this.setState({title: this.props.titleupdate});}
}
render() {
return (
<ToolbarAndroid
title= {this.state.title}
style={styles.toolbar}
/>
);
}
Результат componentWillUpdate не обновляет заголовок панели инструментов, его не вызывается (повторно вынесено).
если я пытаюсь использовать forceUpdate() после обратного вызова обновляет homeviewtitle, он вызывает бесконечный цикл. Я не уверен, какая часть спецификации https://facebook.github.io/react/docs/component-specs.html Im misintepreting. – jsky
Я также попробовал компонентWillMount вместо componentWillUpdate – jsky