How to get state as JSON from Remirror editor in Reactjs

How to get JSON from proseMirror editor using Remirror in Reactjs


We have learned how to setup basic proseMirror editor in React using remirror toolkit. What about accessing the state / JSON ?.

Remirror allow us to use a onChange component and then we have define handler for accessing a state.

First import the component remirror react.

import { OnChangeJSON } from "@remirror/react"; 

Secondly include the component in Remirror editor as follows

const RichTextEditor = () => {
  return (
    <div>
      <WysiwygEditor placeholder="I am a text">
        <OnChangeJSON onChange={handleChange} />
      </WysiwygEditor>
    </div>
  );
};

Let’s define the handleChange and access the state. For simplicity we output the JSON to console.

const handleChange = (json) => {
  console.log(JSON.stringify(json));
};

That’s all , 😊.

Open the code in Sandbox

Author: Manoj

Developer and a self-learner, love to work with Reactjs, Angular, Node, Python and C#.Net

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.