How to pass default value as a prop to Select Component? #4613
-
Common way to use select in react (uncontrolled) <select name="selectedFruit" defaultValue="orange">
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="orange">Orange</option>
</select> controlled function FruitPicker() {
const [selectedFruit, setSelectedFruit] = useState('orange'); // Declare a state variable...
// ...
return (
<select
value={selectedFruit} // ...force the select's value to match the state variable...
onChange={e => setSelectedFruit(e.target.value)} // ... and update the state variable on any change!
>
<option value="apple">Apple</option>
<option value="banana">Banana</option>
<option value="orange">Orange</option>
</select>
);
} how to controll 'Select' Component in 'react-aria-components'
|
Beta Was this translation helpful? Give feedback.
Answered by
devongovett
May 31, 2023
Replies: 1 comment 1 reply
-
https://react-spectrum.adobe.com/react-aria/Select.html#controlled-selection |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
cockyb
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://react-spectrum.adobe.com/react-aria/Select.html#controlled-selection