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

Not working with React.StrictMode #228

Open
xahin96 opened this issue Mar 5, 2023 · 6 comments
Open

Not working with React.StrictMode #228

xahin96 opened this issue Mar 5, 2023 · 6 comments
Labels
bug Something isn't working

Comments

@xahin96
Copy link

xahin96 commented Mar 5, 2023

Environment

  • @editorjs/editorjs version: 2.26.5
  • react-editor-js version: 2.1.0
  • react version: 18.2.0
  • react-dom version: 18.2.0

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

@xahin96 xahin96 added the bug Something isn't working label Mar 5, 2023
@remoblaser
Copy link

Currently facing the same issue. Simple new NextJS installation.

@hellosch
Copy link

May I ask how to solve this problem

@hellosch
Copy link

I see, just remove<React. StrictMode>

@gauravsaluja2006
Copy link

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

@matteobaldini
Copy link

Any way to do this while not removing strict mode?

@TechQuery
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants