您可能希望有一个状态组件,该状态组件在单击按钮之后在按钮旁边显示另一个组件。您需要做的就是跟踪按钮是否被单击:
class MyComponent extends React.Component { constructor(props) { super(props); this.state = { showComponent: false, }; this._onButtonClick = this._onButtonClick.bind(this); } _onButtonClick() { this.setState({ showComponent: true, }); } render() { return ( <div> <Button onClick={this._onButtonClick}>Button</Button> {this.state.showComponent ?<NewComponent /> :null } </div> ); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)