FYI, useLayoutEffect gets you what you're looking for. Since it fires before repaint, you can take measurements and modify the DOM without the user seeing any layout shift.
It's a creative solution though! I always like seeing out of the box thinking on front end problems.