html-to-draftjs in next.js TypeError: htmlToDraft is not a function
Nobody has claimed this yet.
- Dominant language
- HTML
- Stars
- 163
- Forks
- 104
- PR merge metrics
- No merged PRs in 30d
Description
-
So if I import htmlToDraft like this
import htmlToDraft from "html-to-draftjs"; -
I am getting error Window is not defined
So I did
const htmlToDraft = dynamic( () => import("draftjs-to-html").then((mod) => mod.htmlToDraft), { ssr: false } ); -
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
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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