Skip to content

Instantly share code, notes, and snippets.

@loriculberson
Last active October 19, 2022 02:28
Show Gist options
  • Save loriculberson/ae10eba81063ad386563cc77b0d0596b to your computer and use it in GitHub Desktop.
Save loriculberson/ae10eba81063ad386563cc77b0d0596b to your computer and use it in GitHub Desktop.

Counter App

Reference: only use tutorial that use functional components

// function Counter (){}

// const Counter = () => {}

// DO NOT USE CLASS COMPONENTS

// class Counter

// this.setState

  1. Create two buttons.
  2. Button 1 - click to add
  3. Button 2 - click to subtract
  4. Create a function called add and attach it to Button 1 with an onClick
  5. Create a function called subtract and attach it to Button 2 with an onClick
  6. Create a state variable called counter that increases and decreases with the button clicks
import { useState } from 'react'

// inside the Counter component

const [counter, setCounter] = useState(0)
// counter = 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment