Refer
https://stackoverflow.com/a/71342621/15187131
// Or use useLayoutEffect
const firstUpdate = useRef(true);
useLayoutEffect(() => {
if (firstUpdate.current) {
firstUpdate.current = false;
} else {
// do things after first render
}
});