Limlight86
5/5/2020 - 6:49 PM

React state homework #2

React state homework #2

<html lang="en">
  <head>
    <meta charset="UTF-8">
    <title>React Practice</title>
    <script src="https://unpkg.com/react@16.8.4/umd/react.development.js"></script>
    <script src="https://unpkg.com/react-dom@16.8.4/umd/react-dom.development.js"></script>
    <script src="https://unpkg.com/babel-standalone@6/babel.min.js"></script>
  </head>
  <body>
    <div id="root"></div>
    <!--
      INSTRUCTIONS:

      Create two new button tags and corresponding functions. 
      When clicked, the first one should decrease the count by one, 
      The second should reset the count to zero.

    -->
    <script type="text/babel">
      const Counter = () => {

        const [count, setCount] = React.useState(0)

        const incrementCount = () => {
          setCount(count + 1)
        }

          return(
            <div>
              <p>You clicked {count} times</p>
              <button onClick={incrementCount}>
                Add 1
              </button>
              {/* your code goes below this line... */}

            </div>
          )
        }

      ReactDOM.render(<Counter />, document.getElementById('root'))
    </script>
  </body>
</html>