arrow_backBACK TO DRILLS
Blue Beltstate-basicsPREMIUM
useState with an Explicit Generic but No Initial Value
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?