https://github.com/react-monaco-editor/react-monaco-editor/blob/master/src/editor.tsx
take ref from the above link
make a react js , code editor
us react0-final-form
editor should be reusebale
use plain jsx
I'll create a reusable code editor component using Monaco Editor and integrate it with react-final-form. Let's build this using plain JSX instead of TypeScript.
This implementation provides a reusable Monaco Editor component integrated with react-final-form. Here's what each file does:
To use this component, you'll need to install the following dependencies:
npm install monaco-editor react-final-form final-formIf you're using webpack, you'll also need:
npm install monaco-editor-webpack-pluginFor Create React App users, you can use the simpler @monaco-editor/react package:
npm install @monaco-editor/react react-final-form final-formimport React from 'react';
import CodeEditorForm from './components/code-editor-form';
function App() {
const handleSubmit = (values) => {
console.log('Code submitted:', values.code);
};
return (
<div className="app">
<h1>Code Editor</h1>
<CodeEditorForm
initialValues={{
code: 'console.log("Hello world!");',
language: 'javascript',
theme: 'vs-dark'
}}
onSubmit={handleSubmit}
/>
</div>
);
}
export default App;This implementation follows the structure of the react-monaco-editor repository you referenced while adapting it to work with react-final-form and using plain JSX instead of TypeScript.
I need to fix the dependency arrays in the useEffect hooks. Let me update the monaco-editor.jsx component:
Now the useEffect hook properly includes all the dependencies it uses. This ensures that:
The other useEffect hooks in the component are already correctly handling their specific prop changes (value, language, theme), so they don't need to be modified.
This change ensures that the Monaco Editor component will properly respond to all prop changes and avoid potential memory leaks or stale closures.
Would you like me to make any other improvements to the implementation?