Next.js error in MDEditorProps.onChange
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 201
- Avg merge
- 12m
- Merged PRs (30d)
- 1
Description
I have tried this in my Next.js app:
import "@uiw/react-md-editor/markdown-editor.css";
import "@uiw/react-markdown-preview/markdown.css";
import dynamic from "next/dynamic";
import { useState } from "react";
const MDEditor = dynamic(
() => import("@uiw/react-md-editor"),
{ ssr: false }
);
function HomePage() {
const [value, setValue] = useState("**Hello world!!!**");
return (
<div>
<MDEditor value={value} onChange={setValue} />
</div>
);
}
export default HomePage;
but onChange={setValue} always gives me error:
(property) MDEditorProps.onChange?: ((value?: string | undefined) => void) | undefined
Event handler for the onChange event.
Type 'Dispatch<SetStateAction<string>>' is not assignable to type '(value?: string | undefined) => void'.
Types of parameters 'value' and 'value' are incompatible.
Type 'string | undefined' is not assignable to type 'SetStateAction<string>'.
Type 'undefined' is not assignable to type 'SetStateAction<string>'.ts(2322)
Editor.d.ts(16, 5): The expected type comes from property 'onChange' which is declared here on type 'IntrinsicAttributes & MDEditorProps & RefAttributes<ContextStore>'
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 reading Editor.d.ts at line 16 and compare MDEditorProps.onChange with the React state setter shown in the reproduction. Reproduce the TypeScript error in a Next.js app, then verify the callback typing no longer rejects the demonstrated onChange usage.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- next.js, react, typescript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100