-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Editor Duplicating #284
Comments
This issue is caused by a new feature in React18: https://reactjs.org/docs/strict-mode.html#ensuring-reusable-state function App() {
const editor = useRef()
const wrapper = useRef()
const editorWillUnmount = () => {
editor.current.display.wrapper.remove()
wrapper.current.hydrated = false
}
return (
<div className="App">
<CodeMirror
value='<h1>I ♥ react-codemirror2</h1>'
ref={wrapper}
options={{
mode: 'xml',
theme: 'material',
lineNumbers: true
}}
onChange={(editor, data, value) => {
}}
editorDidMount={(e) => editor.current = e}
editorWillUnmount={editorWillUnmount}
/>
</div>
);
} |
@jdz321 Thanks a lot! This works for me too. I'd like to add a note for the ones who use TypeScript like me: this is not type safe solution, since |
for anyone looking for editorDidMount={editorElement => {
(editorRef as React.MutableRefObject<
codemirror.Editor
>).current = editorElement;
}}
editorWillUnmount={() => {
const editorWrapper = (editorRef as React.MutableRefObject<
CodeMirror.Editor
>).current.getWrapperElement();
if (editorWrapper) editorWrapper.remove();
if (wrapperRef.current) {
(wrapperRef.current as { hydrated: boolean }).hydrated = false;
}
}} |
Hi, I use react-codemirror2 7.2.1 and React 18, I got the editor duplicating. When I use React17, it worked fine. Is there anyway to fix ?
The text was updated successfully, but these errors were encountered: