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

How to implement Editor.js in nextjs? #1790

Closed
siddiquiaffan opened this issue Sep 26, 2021 · 6 comments
Closed

How to implement Editor.js in nextjs? #1790

siddiquiaffan opened this issue Sep 26, 2021 · 6 comments

Comments

@siddiquiaffan
Copy link

How to implement Editor.js in nextjs?

I tried to implement Editor.js in Nextjs but I failed to do it.

Here is my code.

import dynamic from 'next/dynamic';

const EditorJs = dynamic(import('react-editor-js'), {
  ssr: false,
  loading: () => <p>Loading ...</p>,
});

const Editor = () => {
  return (
    <>
      <EditorJs />
    </>
  );
};

export default Editor;

Error:

Server Error
ReferenceError: window is not defined

This error happened while generating the page. Any console logs will be displayed in the terminal window.

Can someone help me to implement EditorJs in NextJs?

Code: https://stackblitz.com/edit/nextjs-mckpbw?devtoolsheight=33&file=pages/editor.js

@widn-dev-io
Copy link

I am facing the same thing, have you got the solution?

@mqtik
Copy link

mqtik commented Oct 31, 2021

NextJS is running that server-side, that's why it doesn't work.

Throw a useEffect there, and set a state on mount. That'll only be executed client-side, and show when that state is true.

@wfmonster
Copy link

In my search I found this recent medium article on this.
https://medium.com/@sfazleyrabbi/next-js-editor-js-complete-setup-guide-7136c8bb694e

@Eloi-Perez
Copy link

In my search I found this recent medium article on this. https://medium.com/@sfazleyrabbi/next-js-editor-js-complete-setup-guide-7136c8bb694e

Thank you, that looks very helpful

@siddiquiaffan
Copy link
Author

I am facing the same thing, have you got the solution?

Yep. Unfortunately the same code is working for me.

My code:

import dynamic from 'next/dynamic';

const EditorJs = dynamic(import('react-editor-js'), {
  ssr: false,
  loading: () => <p>Loading ...</p>,
});

const Editor = () => {
  return (
    <>
      <EditorJs />
    </>
  );
};

export default Editor;

Stackblitz Link: https://stackblitz.com/edit/nextjs-mckpbw?file=pages/editor.js

@Eloi-Perez
Copy link

In my search I found this recent medium article on this. https://medium.com/@sfazleyrabbi/next-js-editor-js-complete-setup-guide-7136c8bb694e

Following a bit of that example, I've created a repository with a fully working editor.js in Next.js.
I'm still working on it. But the basic functionality is already there. github.com/Eloi-Perez/my-next-editorjs
Anyone interested feel free to copy or fork the repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants