Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tpye error on onChange #600

Open
zilahir opened this issue Nov 29, 2023 · 1 comment
Open

tpye error on onChange #600

zilahir opened this issue Nov 29, 2023 · 1 comment

Comments

@zilahir
Copy link

zilahir commented Nov 29, 2023

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
Copy link
Member

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

onChange?: (value?: string, event?: React.ChangeEvent<HTMLTextAreaElement>, state?: ContextStore) => void;

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

or

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants