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
I want to use react-draft-wysiwyg to receive input in const [editorState, setEditorState] = useState("";
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
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>
);
}
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
© 2024 OneMinuteCode. All rights reserved.