1.
openDrawer = () => {
this.drawer.openTheDrawer();
};
<Drawer onRef={ref => (this.drawer = ref)}>
.....
<button onClick={() => this.openDrawer()} />
</Drawer>
componentDidMount() {
this.props.onRef(this)
}
openTheDrawer(){
....
};
render(){
<div>
......
{this.props.children}
</div>
}
這樣就可以存取到parent (Drawer) 的function,或是可在parent寫static function,但注意static function 沒有this