stecrv
9/21/2018 - 3:15 PM

basic page

<!DOCTYPE html>
<html>
    <head>
        <script src="https://unpkg.com/@babel/standalone/babel.js"></script>
        <script src="https://unpkg.com/react/umd/react.development.js"></script>
        <script src="https://unpkg.com/react-dom/umd/react-dom.development.js"></script>
    </head>
    <div id="root"></div>
    <script type="text/babel">

      const NowEating = props => <h1>{props.meal}</h1>

      class Menu extends React.Component {
        constructor(props) {
          super(props);
          this.state = {
            meal: "food"
          }
          this.addSideDish =this.addSideDish.bind(this);
        }
        addSideDish = () => {
          this.setState(prevState => {
            return { meal: `${prevState.meal} Changed`}
          })
        }
        render() {
          return (
            <div>
              <NowEating meal={this.state.meal} />
              {(this.state.meal === "food")
                ? <button onClick={this.addSideDish}>Click to change</button>
                : null
              }
            </div>
          )
        }
      }

      ReactDOM.render(
        <Menu />,
        document.getElementById('root')
      )

    </script>
</html>