arrow_backBACK TO DRILLS
Blue Beltstate-basicsPREMIUM
useState Generic Without an Initial Value Infers T | undefined
This component declares state with an explicit generic type argument but no initial value.
REACT_MODULE // 0x42
const [isOpen, setIsOpen] = useState<boolean>();
function toggle() {
setIsOpen(prev => !prev);
}TypeScript reports that prev inside the updater function has type boolean | undefined instead of boolean. Why?