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

editorState.toHtml() is empty #847

Open
Prottoy2938 opened this issue Nov 12, 2020 · 5 comments
Open

editorState.toHtml() is empty #847

Prottoy2938 opened this issue Nov 12, 2020 · 5 comments

Comments

@Prottoy2938
Copy link

editorState.toHtml() returns empty

my code:

import React, { useState } from "react";
import BraftEditor from "braft-editor";
import { Box } from "@chakra-ui/core";
import "braft-editor/dist/index.css";
import { Props } from "./custom-layout-cf.model";

const CustomLayoutCF: React.FC<Props> = (props: Props) => {
  const [editorState, setEditorState] = useState(
    BraftEditor.createEditorState(null)
  );

  const handleChange = (newEditorState) => {
    console.log(newEditorState.toHTML()); //Issue here
    console.log(newEditorState.toText()); //this works fine

    setEditorState(newEditorState);
  };

  return (
    <Box maxWidth="96%" m="0 auto" mt={5} mb={5}>
      <BraftEditor value={editorState} onChange={handleChange} language="en" />
    </Box>
  );
};

export default CustomLayoutCF;

Note that, I'm using: "braft-editor": "^2.3.9" and "draft-js": "^0.11.7"

What to do?

@usamabinnadeem-10
Copy link

I am having the exact same issue, toHtml() returns nothing.

@zseed87
Copy link

zseed87 commented Jan 19, 2021

I have the same problem

@tonyyxliu
Copy link

I got the same problem too, but I finally solved it by npm uninstall draft-js as I saw someone saying that this problem was due to draft-js version. After "npm uninstall", you may need to npm install braft-editor --save back again, just execute it and things may be all right. Hope this will help.

@wuwhs
Copy link

wuwhs commented Mar 11, 2021

I also encountered the same problem. My solution is to reduce the version of braft-editor and lock the version, that is, change braft-editor to the original ^2.3.9 in package.json Change to 2.3.8.
Analyze the reasons:
The braft-editor depends on the updated version of draft-js in the package. If the version of draft-js is reduced, the version of the dependency package draft-js will also be reduced (to 0.10.5), so that it is back to the normal usability before. The version is locked so that the latest minor version dependency package is not actually downloaded.

@liangxp
Copy link

liangxp commented May 17, 2021

这么好的一个编辑器,因为无法toHtml()就这样停摆了?

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

6 participants