Skip to content

Instantly share code, notes, and snippets.

@Thomas465xd
Created May 2, 2025 01:17
Show Gist options
  • Save Thomas465xd/281a2e96b8968e5ce26acaca90d03075 to your computer and use it in GitHub Desktop.
Save Thomas465xd/281a2e96b8968e5ce26acaca90d03075 to your computer and use it in GitHub Desktop.
React Hook Form & React Select
"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