Every line of 'react usestate callback' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.
11 function useStateCallback(setState, fn) { 12 return useCallback((...args) => ( 13 setState((s) => fn(s, ...args)) 14 ), [setState, fn]) 15 }
25 export default function useCallbackRef(): [ 26 TValue | null, 27 (ref: TValue | null) => void, 28 ] { 29 return useState(null) 30 }
70 export function useState(initialState) { 71 return useReducer(invokeOrReturn, initialState); 72 }
38 export function useRef(current) { 39 let [state] = useState({ current }); 40 return state; 41 }
3 export function useStateRef<s>(initialState: S | (() => S)) { 4 const [value, update] = useState(initialState) 5 const ref = useRef({ value, update }) 6 7 ref.current.value = value 8 ref.current.update = update 9 return ref.current 10 }</s>
68 export function useIsMounted() { 69 const isMountedRef = useRef(false); 70 71 const isMounted = useCallback(() => { 72 return isMountedRef.current; 73 }, []); 74 75 useEffect(() => { 76 isMountedRef.current = true; 77 return () => { 78 isMountedRef.current = false; 79 }; 80 }, []); 81 82 return isMounted; 83 }
74 function useWillMount(callback) { 75 const rendered = React.useRef(false) 76 if (!rendered.current) { 77 callback() 78 } 79 rendered.current = true 80 }
40 function useState(...args) { 41 return isFunctional() ? _useState(...args) : useClassState(...args); 42 }
110 export function useCallback( 111 callback: () => mixed, 112 inputs: Array | void | null, 113 ) { 114 const dispatcher = resolveDispatcher(); 115 return dispatcher.useCallback(callback, inputs); 116 }
75 export function useState<s>(initialState: (() => S) | S) { 76 const dispatcher = resolveDispatcher(); 77 return dispatcher.useState(initialState); 78 }</s>