State in React


import React, { useState } from 'react'

const counterExample = () => {
  const [counter, setCounter] = useState(1)

  const onClickHandler = () => {
    setCounter(counter + 1)
  }

  return (
  <div>
    <span>{counter}</span>
    <button onClick={onClickHandler}>Click Me</button>
  </div>
  )

}

Leave a Reply

Your email address will not be published.