React-draft-wysiwyg does not work well in Next.js

Asked 1 years ago, Updated 1 years ago, 52 views

I am thinking of deploying react-draft-wysiwyg in Next.js by referring to the page below.

Easily implement rich text editors running on your browser using React Draft Wysiwyg

What do you want to do

I want to use react-draft-wysiwyg to receive input in const [editorState, setEditorState] = useState("";

Problems/Error Messages you are experiencing

It's not an error, but why
const[editorState, setEditorState]=useState("";

and
<EditorState={editorState} through omitted

If you add , you will not be able to fill in in the production and local environments (vercel can see it).
I would like to implement it because I can't receive the value without this usage, but I don't know the cause.
If anyone understands, please let me know.
Thank you for your cooperation.

https://sample-file.vercel.app/

github
https://github.com/takoyan33/sample-file

Source Codes Affected

JavaScript

import React, {useCallback, useContext, useEffect, useState} from "react";
import dynamic from "next/dynamic";

const Editor = dynamic(
  ( ) = > import ("react-draft-wysiwyg").then ((mod) = > mod.Editor),
  { ssr:false}
);

import {ContentState, convertToRaw, EditorState} from "draft-js";

import "react-draft-wysiwyg/dist/react-draft-wysiwyg.css";

export default function Home() {
  const [editorState, setEditorState] = useState("");

  consthandleImageUpload=useCallback(async(file)=>{
    return wait axios
      .post
      // The process of uploading a file and returning the url of the image after the upload.
      ()
      .then(response)=>{
        return {data:{link:response}};
      })
      .catch(error)=>{
        return error;
      });
  }, []);

  console.log(editorState);

  return(
    <div className="container my-5">
      <Editor
        editorState = {editorState}
        toolbarClassName="toolbarClassName"
        wrapperClassName="wrapperClassName"
        editorClassName = "editorClassName"
        editorStyle={{
          border: "solid 1px lightgray",
          padding: "5px",
        }}
        localization={{locale:"ja"}}}
      />
    </div>
  );
}

reactjs next.js

2022-09-30 16:19

1 Answers

Isn't it a draft-js version problem?

In the official react-draft-wysiwyg document,
It says draft-js 0.10.x is required.

https://jpuri.github.io/react-draft-wysiwyg/#/docs


2022-09-30 16:19

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.