Skip to content

QuizNot attempted

Passing setState down

What is the exact type of a setCount from useState<number> that you pass to a child?
1–4 to choose, Enter to submit
Show answer & explanation

Correct answer:

  • Dispatch<SetStateAction<number>>
  • useState<number> returns a setter typed Dispatch<SetStateAction<number>>, where SetStateAction<number> is number | ((prev: number) => number), so the child can use functional updates.
  • Not (n: number) => void: compiles for direct calls but forbids the updater form.
  • Not Function: untyped, accepts anything.
  • Not SetState<number>: React exports no such type.