CodeMirror + React Integration?

Hi everyone, React dev question here.

Right now the rescript-lang playground is wrapping CodeMirror in a React component, unfortunately the imperative APIs of CodeMirror and the declarative method of React don’t mix that well, or to say it differently, since CM is a separately managed DOM element, it doesn’t make much sense mapping React props for rerendering (lots of useEffect).

So my goal was to embrace the imperative apis instead and keep the React part to the minimum (which basically means to mount the layout and handle the CodeMirror instance as a React.element blackbox).

Does anyone have any previous experience on doing such thing, or even any working code? If there’s nothing out there, I’d probably rewrite the whole thing as a React hook instead, so any ideas / hints are highly appreciated.

(Doesn’t actually have to be CodeMirror, there are probably other JS libs / frameworks that behave similarly.)

I don’t have any direct examples at the ready, but I believe that Three.js is an imperative library that has been wrapped in React as well. So that could be an example worth seeking out (or at least, this was the case a few years ago, it may have changed).