How do we mimic the functionality of useLayoutEffect() in a class component?
Suppose our functional component is
function MyFuncComponent() {
useLayoutEffect(() => {
runSideEffect();
});
}
Assuming this particular side effect requires no cleanup, is this following code equivalent?
class MyClassComponent extends React.Component {
componentDidMount() {
runSideEffect();
}
componentDidUpdate() {
runSideEffect();
}
}
From the doc, it seems they are not exactly equivalent, as multiple scheduled useLayoutEffect()s are flushed in between consecutive renders, but componentDidUpdate()s aren't. Is this understanding correct and if so, how do we mimic useLayoutEffect()?
Updates scheduled inside useLayoutEffect will be flushed synchronously, before the browser has a chance to paint.