mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
at thread-bug 379 B view raw
1import {useCallback} from 'react' 2 3export enum OnceKey { 4 PreferencesThread = 'preferences:thread', 5} 6 7const called: Record<OnceKey, boolean> = { 8 [OnceKey.PreferencesThread]: false, 9} 10 11export function useCallOnce(key: OnceKey) { 12 return useCallback( 13 (cb: () => void) => { 14 if (called[key] === true) return 15 called[key] = true 16 cb() 17 }, 18 [key], 19 ) 20}