Last active
October 14, 2022 06:15
-
-
Save itispx/235dcde8f4af197ef3b3ee279b3d34a5 to your computer and use it in GitHub Desktop.
useTrigger hook
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from "react"; | |
const useTrigger = (func, dependencies) => { | |
const isInitialMount = useRef(true); | |
useEffect(() => { | |
if (isInitialMount.current) { | |
isInitialMount.current = false; | |
} else { | |
func(); | |
} | |
}, dependencies); | |
}; | |
export default useTrigger; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { useEffect, useRef } from "react"; | |
const useTrigger = (func: () => void, dependencies: [] | undefined) => { | |
const isInitialMount = useRef(true); | |
useEffect(() => { | |
if (isInitialMount.current) { | |
isInitialMount.current = false; | |
} else { | |
func(); | |
} | |
}, dependencies); | |
}; | |
export default useTrigger; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment