mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-20 14:39:34 +02:00
feat: Split string
This commit is contained in:
19
src/hooks/useUpdateEffect.ts
Normal file
19
src/hooks/useUpdateEffect.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import { DependencyList, EffectCallback, useEffect, useRef } from "react";
|
||||
|
||||
/**
|
||||
* The useUpdateEffect function is a custom hook that behaves like useEffect, but only runs on updates and not on initial mount.
|
||||
* It takes in an effect function and an optional dependency list as parameters.
|
||||
* It returns nothing.
|
||||
*/
|
||||
const useUpdateEffect = (effect: EffectCallback, deps?: DependencyList) => {
|
||||
const isInitialMount = useRef(true);
|
||||
|
||||
useEffect(() => {
|
||||
if (isInitialMount.current) {
|
||||
isInitialMount.current = false;
|
||||
}
|
||||
return effect();
|
||||
}, deps);
|
||||
};
|
||||
|
||||
export default useUpdateEffect;
|
Reference in New Issue
Block a user