function contentClass(isShow) { if (isShow) { return "content"; } return "content invisible"; } class Toggle extends React.Component { constructor(props) { super(props); this.state = {isShow: false}; this.handleClick = this.handleClick.bind(this); } handleClick() { this.setState(function(prevState) { return {isShow: !prevState.isShow}; }); } render() { return (
Click me to toggle
contents
); } } ReactDOM.render( , document.getElementById('root') );