ShadCN Select compontent troubles
Answered
Rhinelander posted this in #help-forum
RhinelanderOP
...
<Select
required={true}
value={selectedSize!}
onValueChange={(event: React.ChangeEvent<HTMLSelectElement>) => setSelectedSize(event.target.value) }
>
...Code above throws error bellow.
Type '(event: React.ChangeEvent<HTMLSelectElement>) => void' is not assignable to type '(value: string) => void'.
Types of parameters 'event' and 'value' are incompatible.
Type 'string' is not assignable to type 'ChangeEvent<HTMLSelectElement>'.Does anyone know quick solution how would I get value out of this select component.
Answered by B33fb0n3
the
or direcly set the value:
onValueChange is not a default event from the dom. It's from radix and you will only get the selected value. So change your types to this:onValueChange={(newValue: string) => setSelectedSize(newValue)
}or direcly set the value:
onValueChange={setSelectedSize}3 Replies
@Rhinelander typescript
...
<Select
required={true}
value={selectedSize!}
onValueChange={(event: React.ChangeEvent<HTMLSelectElement>) => setSelectedSize(event.target.value) }
>
...
Code above throws error bellow.
Type '(event: React.ChangeEvent<HTMLSelectElement>) => void' is not assignable to type '(value: string) => void'.
Types of parameters 'event' and 'value' are incompatible.
Type 'string' is not assignable to type 'ChangeEvent<HTMLSelectElement>'.
**Does anyone know quick solution how would I get value out of this select component.**
the
or direcly set the value:
onValueChange is not a default event from the dom. It's from radix and you will only get the selected value. So change your types to this:onValueChange={(newValue: string) => setSelectedSize(newValue)
}or direcly set the value:
onValueChange={setSelectedSize}Answer
RhinelanderOP
Thank you!
sure thing