usePrevious
Returns the value from the previous render. Useful for comparing values.
Import
Section titled “Import”import { usePrevious } from 'asterui'function CounterExample() { const [count, setCount] = useState(0) const prevCount = usePrevious(count)
return ( <div> <p>Current: {count}</p> <p>Previous: {prevCount ?? 'N/A'}</p> <Button onClick={() => setCount(c => c + 1)}>Increment</Button> </div> )}Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | T | Current value to track |
Return Value
Section titled “Return Value”| Type | Description |
|---|---|
T | undefined | Previous value (undefined on first render) |