Skip to content
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

could anybody tell me how to install codemirror2 on react18.2.0 #299

Open
Dhimantwalia opened this issue Feb 18, 2023 · 3 comments
Open

Comments

@Dhimantwalia
Copy link

No description provided.

@Pranav-Rustagi
Copy link

Having same issue

@ThaBeanBoy
Copy link

O man, I'm also having the same issue

@martinholecekmax
Copy link

I was able to successfully implement the feature by downgrading the codemirror library to version ^5.65.13. Here's how I did it:

In your package.json file, adjust the dependencies to include these versions:

// package.json
"dependencies": {
    "codemirror": "^5.65.13",
    "react-codemirror2": "^7.2.1",
}

Then, in your main.js file, you should import the necessary language and CSS styles. Here's how:

// main.js
import ReactDOM from 'react-dom/client';

// Importing the necessary language and CSS styles
import 'codemirror/mode/htmlmixed/htmlmixed';
import 'codemirror/lib/codemirror.css';
import 'codemirror/theme/material.css';

// Other necessary imports
import './index.css';
import App from './App.js';

ReactDOM.createRoot(document.getElementById('root') as HTMLElement).render(
  <App />
);

Finally, here is the component that utilizes the editor. You can find it in the html-editor.js file:

// html-editor.js
import React from 'react';
import { Controlled as ControlledEditor } from 'react-codemirror2';

const HtmlEditor = ({ field, value, onChange }) => {
  return (
    <ControlledEditor
      value={value}
      options={{
        lineWrapping: true,
        lint: true,
        lineNumbers: true,
        mode: 'htmlmixed',
        htmlMode: true,
        theme: 'material',
      }}
      onBeforeChange={(editor, data, value) => {
        onChange({ field, value });
      }}
    />
  );
};

export default HtmlEditor;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants