Socket
Socket
Sign inDemoInstall

@react-stately/select

Package Overview
Dependencies
Maintainers
2
Versions
714
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


Version published
Weekly downloads
905K
increased by3.47%
Maintainers
2
Weekly downloads
 
Created

Package description

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

Readme

Source

@react-stately/select

This package is part of react-spectrum. See the repo for more details.

FAQs

Package last updated on 20 Dec 2023

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc