🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

@react-stately/select

Package Overview
Dependencies
Maintainers
2
Versions
969
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-stately/select

Spectrum UI components in React

3.6.12
latest
Source
npm
Version published
Weekly downloads
1.3M
7.39%
Maintainers
2
Weekly downloads
 
Created

What is @react-stately/select?

@react-stately/select is a library that provides state management for select components in React applications. It is part of the React Spectrum collection of libraries, which are designed to work together to build accessible, high-quality user interfaces.

What are @react-stately/select's main functionalities?

Basic Select State Management

This feature allows you to manage the state of a select component, including the list of items and the currently selected item.

import { useSelectState } from '@react-stately/select';

const state = useSelectState({
  items: [
    { key: 'red', name: 'Red' },
    { key: 'green', name: 'Green' },
    { key: 'blue', name: 'Blue' }
  ],
  selectedKey: 'red'
});

console.log(state.selectedKey); // 'red'

Handling Selection Changes

This feature allows you to handle changes in the selection state, providing a callback function that is called whenever the selected item changes.

import { useSelectState } from '@react-stately/select';

const state = useSelectState({
  items: [
    { key: 'red', name: 'Red' },
    { key: 'green', name: 'Green' },
    { key: 'blue', name: 'Blue' }
  ],
  selectedKey: 'red',
  onSelectionChange: (key) => console.log('Selected:', key)
});

state.setSelectedKey('green'); // Logs: 'Selected: green'

Multiple Selection

This feature allows you to manage multiple selections within a select component, including handling changes to the set of selected items.

import { useSelectState } from '@react-stately/select';

const state = useSelectState({
  items: [
    { key: 'red', name: 'Red' },
    { key: 'green', name: 'Green' },
    { key: 'blue', name: 'Blue' }
  ],
  selectedKeys: new Set(['red']),
  selectionMode: 'multiple',
  onSelectionChange: (keys) => console.log('Selected keys:', keys)
});

state.setSelectedKeys(new Set(['green', 'blue'])); // Logs: 'Selected keys: Set { 'green', 'blue' }'

Other packages similar to @react-stately/select

FAQs

Package last updated on 11 Apr 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts