monaco-editor/react onClick event doesn’t fire


I am using monaco-editor/react in my Next.js application, and everything works well.
I need to handle onClick event of the editor, but the event never fires.
here is my code:

import Editor from "@monaco-editor/react";
import { useRef, useState } from "react";

export default function MyEditor(){
    const editorRef = useRef(null);
    const [code,setCode]=useState("");

    function handleEditorDidMount(editor, monaco) {
        editorRef.current = editor;
    }

    function onChange(e) {
        setCode(e);
    }

    return(<Editor
            height="90vh"
            defaultLanguage="javascript"
            defaultValue="// some comment"
            value={code}
            onMount={handleEditorDidMount}
            onChange={onChange}
            onClick={() => {
              // this is never called
              alert("Clicked");
            }}
     />);
}

Source: React – Stack Overflow

October 11, 2021
Category : News
Tags: monaco-editor | next.js | reactjs

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.