Download chakra-ui/packages/react/src/hooks/use-update-effect.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 610 Bytes
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/hooks/use-update-effect.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset@f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/hooks/use-update-effect.ts
-
curl -L -o use-update-effect.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/f5071caa249115f3b590492f1c8eb471e02aae4b/chakra-ui/packages/react/src/hooks/use-update-effect.ts
610 Bytes
| "use client" | |
| import { useEffect, useRef } from "react" | |
| export const useUpdateEffect: typeof useEffect = (effect, deps) => { | |
| const renderCycleRef = useRef(false) | |
| const effectCycleRef = useRef(false) | |
| useEffect(() => { | |
| const isMounted = renderCycleRef.current | |
| const shouldRun = isMounted && effectCycleRef.current | |
| if (shouldRun) { | |
| return effect() | |
| } | |
| effectCycleRef.current = true | |
| // eslint-disable-next-line react-hooks/exhaustive-deps | |
| }, deps) | |
| useEffect(() => { | |
| renderCycleRef.current = true | |
| return () => { | |
| renderCycleRef.current = false | |
| } | |
| }, []) | |
| } | |