Unable to get the correct type for onChange argument when using CreatableSelect #5641
Unanswered
weehongkoh
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm using
CreateableSelect
dropdown that allows the user to create a new option.Attached code below.
I tried to set the onChange method with the type
SingleValue<CardOptionProp>
to update the selected valuesetValue()
provided by React Hook Form and also update the selected value and display it on the CreateableSelect selected options field.However, I received a lint error complaint Type
'(newValue: SingleValue<CardOptionProp>) => void' is not assignable to type '(newValue: SingleValue<CategoryOptionProp> | MultiValue<CategoryOptionProp>, actionMeta: ActionMeta<CategoryOptionProp>) => void'
, which I don't know who to resolve it.I also tried to include the
MultiValue<CategoryOptionProp>
based on the suggested lint error. However, it showed me a different prompt error which didn't make sense to me, and the problem was solved after I changed the type to SingleValue.But I would like to avoid
any
type as much as possible. May I know if there's any other workaround?If you would prefer to read the entire source code,
This is the link to the file itself.
https://github.com/weehongayden/finance-app/blob/expense/src/components/expenses/Form.tsx#L142
Beta Was this translation helpful? Give feedback.
All reactions