Next.js Discord

Discord Forum

ShadCN Select compontent troubles

Answered
Rhinelander posted this in #help-forum
Open in Discord
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 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}
View full answer

3 Replies