How do you get the values from the select element? #97
-
My question is... |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
Thanks for your feedback! For the basics of how to use this component, you should check out the docs for the original react-select component: https://react-select.com/home But I can also give you a simple example of how to do so, you just need to use the import { useState } from "react";
import { Select } from "chakra-react-select";
export const flavors = [
{ value: "vanilla", label: "Vanilla" },
{ value: "chocolate", label: "Chocolate" },
{ value: "strawberry", label: "Strawberry" },
{ value: "salted-caramel", label: "Salted Caramel" }
];
const Example = () => {
const [selectedOptions, setSelectedOptions] = useState([]);
return (
<Select
isMulti
name="flavors"
options={flavors}
placeholder="Select some flavors..."
// Add these props to the component
value={selectedOptions}
onChange={setSelectedOptions}
/>
);
}; |
Beta Was this translation helpful? Give feedback.
-
thanks, great resposnse |
Beta Was this translation helpful? Give feedback.
Thanks for your feedback! For the basics of how to use this component, you should check out the docs for the original react-select component: https://react-select.com/home
But I can also give you a simple example of how to do so, you just need to use the
value
andonChange
props to manually keep track of the value using state: