init
This commit is contained in:
17
frontend/hooks/use-store.ts
Normal file
17
frontend/hooks/use-store.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import { useState, useEffect } from "react";
|
||||
/**
|
||||
* This hook fix hydration when use persist to save hook data to localStorage
|
||||
*/
|
||||
export const useStore = <T, F>(
|
||||
store: (callback: (state: T) => unknown) => unknown,
|
||||
callback: (state: T) => F
|
||||
) => {
|
||||
const result = store(callback) as F;
|
||||
const [data, setData] = useState<F>();
|
||||
|
||||
useEffect(() => {
|
||||
setData(result);
|
||||
}, [result]);
|
||||
|
||||
return data;
|
||||
};
|
||||
Reference in New Issue
Block a user