jpuri / jpuri/html-to-draftjs

html-to-draftjs in next.js TypeError: htmlToDraft is not a function

Open
#83 15 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
HTML
Stars
163
Forks
104
PR merge metrics
No merged PRs in 30d

Description

  1. So if I import htmlToDraft like this
    import htmlToDraft from "html-to-draftjs";

  2. I am getting error Window is not defined
    So I did
    const htmlToDraft = dynamic( () => import("draftjs-to-html").then((mod) => mod.htmlToDraft), { ssr: false } );

  3. Then error is not coming but when I use it like
    `useEffect(() => {
    props.getDescription().then((res) => {
    // console.log(res.data);
    const blocksFromHtml = htmlToDraft(res.data);
    const { contentBlocks, entityMap } = blocksFromHtml;
    const contentState = ContentState.createFromBlockArray(
    contentBlocks,
    entityMap
    );
    setEditor(EditorState.createWithContent(contentState));

    });
    }, []);`

Error is coming: TypeError: htmlToDraft is not a function

@jpuri Can you help me?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the import and dynamic-loading examples in a Next.js app, then inspect which export is returned by the html-to-draftjs import. Done means htmlToDraft can be called in the shown useEffect without either the Window is not defined or TypeError error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, react
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.