Avoid stale state in callbacks with this hook. Auto updates values using a ref.
Argument value | Type | Description |
---|---|---|
value | T | The value which needs to be fresh at all times. Probably best used with functions |
preferLayoutEffect | boolean | Should the value be updated using a layout effect or a passive effect. Defaults to false. |
Return value | Type | Description | Default value |
---|---|---|---|
ref | RefObject | A ref containing the fresh value | () => null |
Join our discord server! You can click the floating discord icon at the bottom right of the screen and chat with us!