How to use useState with Select? #6105
-
Hi,
On 1, I don't see On 2, this one I'm completely thrown by. Am I not passing in the right value to selectedKey? Any help would be greatly appreciated import { useState } from 'react';
import type { Key } from 'react-aria-components';
let statusOptions = [
{ name: 'Applied' },
{ name: 'Offered' },
{ name: 'Rejected' },
];
const [status, setStatus] = useState<Key>('Applied');
return (
<Select
items={statusOptions}
selectedKey={status}
onSelectionChange={(selected) => setStatus(selected)}
>
<Label>Status</Label>
<Button>
<SelectValue />
<ChevronDownIcon />
</Button>
<Popover>
<ListBox>
<ListBoxItem>
<Status>Applied</Status>
</ListBoxItem>
<ListBoxItem>
<Status>Offered</Status>
</ListBoxItem>
<ListBoxItem>
<Status>Rejected</Status>
</ListBoxItem>
</ListBox>
</Popover>
</Select>
) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
And to access the selection state from inside, you can use render props or contexts. If you do that, you don't even need to do a fully controlled version. |
Beta Was this translation helpful? Give feedback.
And to access the selection state from inside, you can use render props or contexts. If you do that, you don't even need to do a fully controlled version.