score:1

hooks are called at the root level of a functional component, or by other hooks. hooks must never be called conditionally, or from event handlers. but you can call any function returned by the hook at pretty much any point.

i'm not sure what usepoints() does exactly, but here is how you would set this up using usestate

function mycomponent() {
  const [points, setpoints] = usestate(0)

  function changequiz(e) {
    if (e.target.innerhtml === quiz.correct) setpoints(points + 1)
    // other logic
  }

  return <div>
    {/* component jsx here */}
  </div>
}

in this example setpoints() is called conditionally, which is fine because it is not a hook. it's a function the hook returns.


Related Query

More Query from same tag