'Draft js issues, Editor state not being set. Editor.createWithContent doesnt work

  export default function WysiWyg({
      description,
      handleDescription,
      descreaseDescriptionsCount,
    }) {
      const dispatch = useDispatch();
      const [editorState, setEditorState] = React.useState(() =>
        EditorState.createEmpty()
      );
    
      React.useEffect(() => {
        const editorcontent = editorState.getCurrentContent();
        dispatch(
          SET_DESCRIPTIONS({
            name: description.name,
            value: JSON.stringify(convertToRaw(editorcontent)),
          })
        );
      }, [editorState]);
    
      React.useEffect(() => {
        if (description.value) {
          let content = EditorState.createWithContent(
            convertFromRaw(JSON.parse(description.value))
          );
          setEditorState(content);
        }
      }, [description.value]);
      return (
   
        <div className="flex flex-row">
          <div
            style={{
              border: "1px solid black",
              padding: "2px",
              minHeight: "400px",
            }}
          >
            <Editor
              editorContent={editorState}
              onEditorStateChange={setEditorState}
            />
          </div>
          <div
            className="cursor-pointer ml-10 top-10 flex mt-10"
            onClick={(e) => {
              descreaseDescriptionsCount(e);
              dispatch(DELETE_DESCRIPTIONS(description.name));
            }}
          >
            <MinusCircleIcon width={20} height={20} />
          </div>
        </div>
      );
    }

So here is my code. I am trying to create a draftjs wysiwyg but EditorState.createwithcontent does not set any value in editor box.

I am not able to understand what is the issue with this.

Can someone show me a fix for this ?

I have looked up around and not have any success.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source