uiwjs / react-md-editor

A simple markdown editor with preview, implemented with React.js and TypeScript.
https://uiwjs.github.io/react-md-editor
MIT License
2.03k stars 149 forks source link

tpye error on `onChange` #600

Open zilahir opened 7 months ago

zilahir commented 7 months ago

When provdigin a the setState Event handler for the onChange event, there is a type mismatch:

const [value, setValue] = useState("**Hello world!!!**");
<MDEditor value={value} onChange={setValue} />
Type 'Dispatch<SetStateAction<string>>' is not assignable to type '(value?: string | undefined, event?: ChangeEvent<HTMLTextAreaElement> | undefined, state?: ContextStore | 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)

versions:


"@uiw/react-md-editor": "^4.0.1",
"typescript": "^4.9.5",
jaywcjlove commented 7 months ago

@zilahir I don't know how to handle this type

https://github.com/uiwjs/react-md-editor/blob/8b2586891dc5a3e5f8f89895a2ffa454f860d171/core/src/Types.ts#L27

<MDEditor value={value} onChange={setValue as MDEditorProps['onChange']} />

or

<MDEditor value={value} onChange={(val) => setValue(val)} />