useLayoutEffect

Almost identical to useEffect, but it fires synchronously after all DOM mutations.

This has the same syntax as useEffect.

Use this to read layout from the DOM and synchronously re-render.

useEffect is better to avoid blocking visual updates, so try that first, and only use useLayoutEffect if useEffect doesn't work.

This is an option for if window or document are needed, like in ShareButtons.

useLayoutEffect(() => {console.log(count);}, [count]);

If you're manipualting the DOM in a way that the user can see, you should use useLayoutEffect.

If you're not manipulating the DOM, or if it's in a way that the user can't see, use useEffect

Example

You've clicked 0 times!