Jungwoo-An / react-editor-js

⚛️📝The unofficial editor-js component for React
https://codesandbox.io/s/react-editor-js-v2-34bfl
MIT License
951 stars 77 forks source link

Not working with React.StrictMode #228

Open xahin96 opened 1 year ago

xahin96 commented 1 year ago

Environment

Code

Editor Component

import { createReactEditorJS } from 'react-editor-js'
import { EDITOR_JS_TOOLS } from './tools'
import { useState, useEffect, useRef, useCallback } from 'react'

const ReactEditorJS = createReactEditorJS()

export default function REJS() {
  const initialData = {
    ...
  }

  const [called, setCalled] = useState(false)

  const editorCore = useRef(null)
  const reload = useRef(false)

  useEffect(() => {
    if (reload.current == false) {
      reload.current = true
    }
  }, [])

  const handleInitialize = useCallback((instance) => {
    console.log('ins=>', instance)
    editorCore.current = instance
  }, [])

  const handleSave = useCallback(async () => {
    const savedData = await editorCore.current.save()
    console.log('=>', savedData)
  }, [])

  return (
    <ReactEditorJS
      tools={EDITOR_JS_TOOLS}
      onInitialize={handleInitialize}
      onChange={handleSave}
      data={initialData}
      placeholder="Start writing or click + for more options"
    />
  )
}

App component

import REJS from './components/React Editor JS/rejs'

function App() {
  return (
    <div className="App">
      Hello
      <div>
        Start
        <REJS />
        End
      </div>
    </div>
  );
}

export default App;

Describe

I'm trying to use the default functionalities but while using strict mode, the editor is not loading on the DOM. With strict mode: image Without strict mode: image

remoblaser commented 1 year ago

Currently facing the same issue. Simple new NextJS installation.

hellosch commented 1 year ago

May I ask how to solve this problem

hellosch commented 1 year ago

I see, just remove

gauravsaluja2006 commented 1 year ago

Thanks! I was wondering what i did wrong. Not sure what's causing this, even i had to remove to get it to work.

matteobaldini commented 1 year ago

Any way to do this while not removing strict mode?

TechQuery commented 1 year ago

Currently facing the same issue. Simple new NextJS installation.

@remoblaser To shut down React Strict Mode for now: https://nextjs.org/docs/pages/api-reference/next-config-js/reactStrictMode

ZulluBalti commented 3 months ago

any solution other than removing strict mode?