Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

187
Views
SaveData is not output and instanceRef null

I have a problem with react-editor-js library. I'm trying to get data from it, but it doesn't output and when I check instanceRef it's null. Here is the code.

const Create = () => {
    const instanceRef = React.useRef(null);
    let data = { '1': 'test' }

    async function handleSave() {
        const savedData = await instanceRef.current.save()
        console.log(savedData)
    }
    return (
        <div>
            <Header Name='Создание'/>
            <Menu/>
            <div className="editor">
                <ReactEditorJS
                    instanceRef={(instance) => (instanceRef.current = instance)}
                    tools={EDITOR_JS_TOOLS}
                    data={data}
                    onChange={() => handleSave}
                />
            </div>
        </div>
    );
};

If I use

onChage={() => handleSave}

I get this error.

Uncaught (in promise) TypeError: Cannot read properties of null (reading 'save')

Thanks for your help!

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

As per ReactEditorJS docs - you should use onInitialize to save your instance on initialize.

So in your case try this -

const Create = () => {
    const instanceRef = React.useRef(null);
    let data = { '1': 'test' }

    async function handleSave() {
        const savedData = await instanceRef.current.save()
        console.log(savedData)
    }
    return (
        <div>
            <Header Name='Создание'/>
            <Menu/>
            <div className="editor">
                <ReactEditorJS
                    //changed instanceRef to onInitialize
                    onInitialize={(instance) => (instanceRef.current = instance)}
                    tools={EDITOR_JS_TOOLS}
                    data={data}
                    //need to add '()' to call handleSave
                    // or you can change it to onChange={handleSave}
                    onChange={() => handleSave()}
                />
            </div>
        </div>
    );
};

References - How to access editor-js instance?

Note - I have not tried this solution but by reading the documentation I have added this answer, let me know if it does not work.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!