i guess i found the root cause of the inconsistent behavior. there is another hook called uselayouteffect

uselayouteffect the signature is identical to useeffect, but it fires synchronously after all dom mutations. use this to read layout from the dom and synchronously re-render. updates scheduled inside uselayouteffect will be flushed synchronously, before the browser has a chance to paint.

the uselayouteffect will block the painting while the useeffect will not. that confirm and explains my guess that the didfocus event had fired, but it didn't trigger the listener since it miss the timing

so in my case, i have to use uselayouteffect instead of useeffect


Related Query

More Query from same tag