Delays the update of a value until the input has stopped changing for a certain time. This is different from React's built-in useDeferredValue because you can set the delay yourself.
The value to defer and output.
The amount of time to wait after input has stopped changing before outputting it.
The deferred input value.
const DemoUseDefer = () => { const [value, setValue] = useState(""); const displayValue = useDefer(value, 500); return ( <div> <input type="text" value={value} onInput={(e) => setValue((e.target as HTMLInputElement).value)} /> <ul> {displayValue} </ul> </div> );}; Copy
const DemoUseDefer = () => { const [value, setValue] = useState(""); const displayValue = useDefer(value, 500); return ( <div> <input type="text" value={value} onInput={(e) => setValue((e.target as HTMLInputElement).value)} /> <ul> {displayValue} </ul> </div> );};
Delays the update of a value until the input has stopped changing for a certain time. This is different from React's built-in useDeferredValue because you can set the delay yourself.