📦 add skip react srictmode

Adding new hooks as a replacement for `useEffects(() => {}, [])` in React by adding React strict mode safety, which
means that this function will only be executed once, even in development mode.
This commit is contained in:
2025-08-31 23:33:04 +07:00
parent 2d671b189a
commit 41babd10a1

View File

@ -0,0 +1,14 @@
import { useEffect, useRef } from "react";
const useRunOnce = (callback: () => void | Promise<void>) => {
const calledRef = useRef(false);
useEffect(() => {
if (calledRef.current) return;
calledRef.current = true;
void callback();
}, [callback]);
};
export default useRunOnce;