我有以下类组件-
https://pastebin.com/WigZksAq
我想将面板移动到单独的文件-
const Panel1 = props => (
<Panel id='Panel1'>
<PanelHeader>Panel 1</PanelHeader>
<Group>
<CellButton onClick={ () => this.setState({ activePanel: 'panel2' }) }>
Go to panel 2
</CellButton>
</Group>
</Panel>
);
但我不明白如何修改主类组件的状态。
好的,我找到了解决方案:
<Panel1 id='Panel1' go={active_panel => this.setState({ activePanel: active_panel })}></Panel1>
在父组件中,以及
<CellButton onClick={props.go.bind(this, 'panel2')}>
Go to panel 2
</CellButton>
它看起来很难看,但很管用,将来我计划开始使用redux。