react-md-editor icon indicating copy to clipboard operation
react-md-editor copied to clipboard

tpye error on `onChange`

Open zilahir opened this issue 2 years ago • 1 comments

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",

zilahir avatar Nov 29 '23 22:11 zilahir

@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)} />

jaywcjlove avatar Nov 30 '23 02:11 jaywcjlove