mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-01-18 23:16:59 +01:00
13 lines
354 B
TypeScript
13 lines
354 B
TypeScript
import { useEffect, useState } from 'react';
|
|
|
|
/**
|
|
* Like useState, except it will update the value when the default value changes
|
|
*/
|
|
export function useStateSyncDefault<T>(defaultValue: T) {
|
|
const [value, setValue] = useState(defaultValue);
|
|
useEffect(() => {
|
|
setValue(defaultValue);
|
|
}, [defaultValue]);
|
|
return [value, setValue] as const;
|
|
}
|