Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-codemirror2 creating two editors

I am using codemirror and react-codemirror2 to create code editor, I am using the Controlled component once but its showing two editors, When I type on the first editor it is reflecting on the 2nd one

enter image description here

Code:

import "codemirror/lib/codemirror.css";
import "codemirror/theme/eclipse.css";
import "codemirror/mode/javascript/javascript";
import { Controlled as REditor } from "react-codemirror2";

const CreatePolicy = () => {
    const [value, setValue] = useState<string>("");
    return (
    <div className="create-policy-container">
         <REditor
            className="code-mirror-wrapper"
            onBeforeChange={(editor, data, value) => {
               setValue(value);
             }}
            value={value}
            options={{
            lineWrapping: true,
            lint: true,
            mode: "css",
            theme: "eclipse",
            lineNumbers: true,
           }}
         /> 
    </div>
  );
};

export default CreatePolicy;
like image 873
Veera Silamban Avatar asked Jul 21 '26 13:07

Veera Silamban


2 Answers

I was having the same issue. What I did to solve it was deleting the ReactStrictMode component from the Index.js file. Though I don't know why that works, for I only did what it said here

like image 63
Pablo Clavijo Avatar answered Jul 24 '26 05:07

Pablo Clavijo


Just paste this in your css file ->

.react-codemirror2 > .CodeMirror:first-child { display: none; }
like image 38
Jai Jain Avatar answered Jul 24 '26 06:07

Jai Jain



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!