I can't seem to find a way to set the initial selected value. #228
Replies: 2 comments 2 replies
-
The easiest way is to create your const Example = () => {
const [selectedColors, setSelectedColors] = useState([colorOptions[0]]);
const [selectedColor, setSelectedColor] = useState(colorOptions[0]);
return (
<Container mb={16}>
<FormControl p={4}>
<FormLabel>chakra-react-select Multi Select</FormLabel>
<Select
name="colors"
placeholder="Select some colors..."
isMulti
options={colorOptions}
value={selectedColors}
onChange={setSelectedColors}
/>
</FormControl>
<FormControl p={4}>
<FormLabel>chakra-react-select Single Select</FormLabel>
<Select
name="colors"
placeholder="Select a color..."
options={colorOptions}
value={selectedColor}
onChange={setSelectedColor}
/>
</FormControl>
</Container>
);
}; In the case of a multi-select, set your initial value to an array of option objects. In a single select, set it to just one option object. CodeSandbox: https://codesandbox.io/s/chakra-react-select-initial-value-9gljzp?file=/example.js |
Beta Was this translation helpful? Give feedback.
-
Hello guys, I've tried to apply onChange on this typescript example (https://codesandbox.io/s/chakra-react-select-ts-demo-vz9ut?file=/app.tsx) but I'm getting these erros:
I'm new at typescript and frontend. Any help would be very appreciated! |
Beta Was this translation helpful? Give feedback.
-
Description
I read the docs and looked at the available examples and there is no mention of any way to set the selected value/s
chakra-react-select Version
4
Link to Reproduction
No response
TypeScript?
Steps to reproduce
No response
Operating System
Additional Information
No response
Beta Was this translation helpful? Give feedback.
All reactions