Capítulo 57 de 116
useInsertionEffect(setup) runs before any DOM mutations from the current commit are applied — a highly specialized Hook meant almost exclusively for CSS-in-JS library authors who need to inject <style> tags before layout is read by anything else, not for application code.
useInsertionEffect fires before useLayoutEffect, which fires before useEffect — this Hook exists specifically to guarantee styles are in the DOM before layout effects run and could read stale/missing styles.useLayoutEffect, DOM refs aren't yet attached when useInsertionEffect runs, since it fires even earlier in the commit sequence — it's only appropriate for injecting global style rules, not for reading/measuring specific elements.useEffect: useInsertionEffect(setup), with setup optionally returning cleanup, but without a dependency-array-driven "skip if unchanged" nuance being the primary concern the way it is for useEffect.useLayoutEffect or useEffect instead, not this Hook.useInsertionEffect → useLayoutEffect → useEffect) rather than the mechanics.