mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-27 11:51:13 +01:00
Obfuscate environment variables
This commit is contained in:
12
src-web/hooks/useStateSyncDefault.ts
Normal file
12
src-web/hooks/useStateSyncDefault.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user