Documentation Index
Fetch the complete documentation index at: https://mintlify.com/rijvi-mahmud/shaddy/llms.txt
Use this file to discover all available pages before exploring further.
useDefault is a React hook that manages a stateful value and automatically substitutes a default fallback whenever the state would otherwise become null or undefined. This removes the need to sprinkle value ?? defaultValue throughout your JSX — the hook guarantees the returned value is always of type T, never nullable. It is ideal for form fields, configuration panels, and any scenario where a sensible default should silently replace a missing value.
Installation
Signature
Parameters
The value the state is initialised with. Can be any type, including objects and arrays.
The fallback value that is used whenever the setter receives
null or undefined. Must be the same type as initialValue.Return Value
The current state value. This is always of type
T — it is never null or undefined because the hook automatically replaces those with defaultValue.A setter function. When called with a non-nullish value it stores that value directly; when called with
null or undefined it stores defaultValue instead.Usage
With Objects
Notes
- The fallback is applied via the nullish coalescing operator (
??), so onlynullandundefinedtrigger the default — falsy values like0,false, or""are stored as-is. - The returned value is typed as
T(notT | null | undefined), so downstream code never needs additional null checks. - The hook is generic with a default type parameter of
any, but TypeScript infersTautomatically from yourinitialValueargument in most cases.