The useRef hook can be used to store any mutable value, so you could store a boolean indicating if it's the first time the effect is being run.
Example
const { useState, useRef, useEffect } = React;
function MyComponent() {
const [count, setCount] = useState(0);
const isFirstRun = useRef(true);
useEffect (() => {
if (isFirstRun.current) {
isFirstRun.current = false;
return;
}
console.log("Effect was run");
});
return (
Clicked {count} times
);
}
ReactDOM.render(
,
document.getElementById("app")
);