Created
May 2, 2025 01:17
-
-
Save Thomas465xd/281a2e96b8968e5ce26acaca90d03075 to your computer and use it in GitHub Desktop.
React Hook Form & React Select
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use client" | |
import { useEffect, useState } from "react"; | |
import Select from "react-select"; | |
export default function CreateOrderForm() { | |
const [flavors, setFlavors] = useState([]); | |
useEffect(() => { | |
console.log(flavors) | |
}, [flavors]) | |
const selectFalvor = flavors => { | |
setFlavors(flavors) | |
} | |
const options = [ | |
{ id: 'chocolate', name: 'Chocolate' }, | |
{ id: 'strawberry', name: 'Strawberry' }, | |
{ id: 'vanilla', name: 'Vanilla' } | |
] | |
return ( | |
<Select | |
options={options} | |
isMulti | |
onChange={option => selectFalvor(option)} | |
getOptionValue={(options) => options.id} | |
getOptionLabel={(options) => options.name} | |
placeholder="Select a flavor" | |
noOptionsMessage={() => "No flavors found"} | |
/> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment