react component did mount functional component code example
Example 1: how to use componentdidmount in functional component
useEffect(() => {
if(!props.fetched) {
props.fetchRules();
}
console.log('mount it!');
}, []);
useEffect({
your code here
})
useEffect(() => {
}, [yourDependency]);
useEffect(() => {
return () => {
}
}, [yourDependency]);
Example 2: useeffect on update
const isInitialMount = useRef(true);
useEffect(() => {
if (isInitialMount.current) {
isInitialMount.current = false;
} else {
}
});