Tsallaka zuwa abun ciki
Justice Tech School

Custom Hooks

A custom hook is a function starting with use that calls other hooks.

Example
function useToggle(initial = false) {
  const [on, setOn] = useState(initial);
  const toggle = () => setOn((o) => !o);
  return [on, toggle];
}

Exercise

Naming rule.

function Toggle() {}

Quiz Test

How must a custom hook be named?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.