Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@react-stately/select

Package Overview
Dependencies
Maintainers
2
Versions
789
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.0.0-nightly-db51509aa-240909
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
482K
decreased by-49.99%
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 09 Sep 2024

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc