Hacker News new | ask | show | jobs
by karaokeyoga 1184 days ago
useLayoutEffect is called after the render cycle but before the “paint”. useMemo is called during the render cycle (i.e. immediately).

You can confirm this via console.log:

useMemo(() => console.log(1), [])

console.log(2)

… will print 1 then 2.

If you replace useMemo with useLayoutEffect, you’ll get 2 then 1.