ComponentDidmount React Hooks
useEffect(() => {
// Your code here
}, []);
rahul_the_rock
useEffect(() => {
// Your code here
}, []);
export default function useDidMountHook(callback) {
const didMount = useRef(null)
useEffect(() => {
if (callback && !didMount.current) {
didMount.current = true
callback()
}
})
}
const num = 5
useEffect(() => {
console.log("I will only run if my deps change: ", num)
}, [num])
const msg = "some message"
const myFunc = useCallback(() => {
console.log(msg)
}, [msg])
useEffect(() => {
myFunc()
}, [myFunc])
useEffect(() => {
// componentWillUnmount
return () => {
// Your code here
}
}, [yourDependency]);
useEffect(() => {
console.log("I have been mounted")
}, [])
useEffect(() => {
const someFunc = () => {
console.log("Function being run after/on mount")
}
someFunc()
}, [])
useEffect(() => {
// Your code here
}, [yourDependency]);
useEffect(() => {
// <div>{count}</div>
}, [count]);