This doesn't work but I'd expect it to.
@gaearon Could it be that useMutationEffect() is being called synchronously as the DOM mutation, so there is no DOM element to even add a ref to?
I believe you would have to use useLayoutEffect() in this case, as it fires synchronously after all DOM mutations. Allowing the ref to "settle"
@Caryyon
I believe you would have to use useLayoutEffect() in this case, as it fires synchronously after all DOM mutations. Allowing the ref to "settle"
Ya it works @gaearon
What's the use of useMutationEffect() if no refs are set by the time it runs? I'm struggling to think of what it could be used for if you don't have any live handles to the DOM within its callback.
I also just noticed this, and that useLayoutEffect indeed lets you get a working reference.
Now that useMutationEffect has been banished to /dev/null this is possibly "fixed"?