据我所知,你想要的是能够在兄弟姐妹之间共享数据
Inner
AComponentNeedingTheHolderContent
.
使用React的方法是将状态保持在外部,并定义可以修改此状态并将其传递给内部的函数。例如:
@observer class Inner {
clickHandler = (event) => {
this.props.modify_something(event.value);
}
render() {
return <div>
<Something onClick={this.clickHandler}/>
</div>
}
@observer class Outer {
@observable something = 'something';
@action
modify_something = (modified_value) => {
this.something = modified_value;
}
render() {
return <div>
<Inner modify_something={this.modify_something} />
<AComponentNeedingTheHolderContent something={this.something}/>
</div>
}
}