New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

react-stately

Package Overview
Dependencies
Maintainers
2
Versions
854
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-stately

Spectrum UI components in React

  • 3.22.1-nightly.3863
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
708K
increased by2.82%
Maintainers
2
Weekly downloads
 
Created

What is react-stately?

react-stately is a library that provides state management utilities for building accessible and robust React components. It is part of the React Spectrum collection of libraries developed by Adobe, which aims to provide a comprehensive set of tools for building adaptive, accessible, and robust user interfaces.

What are react-stately's main functionalities?

useListState

The useListState hook manages the state for a list of items, including selection and focus management. This example demonstrates how to initialize a list with some items and manage their state.

import { useListState } from 'react-stately';

function MyListComponent(props) {
  let state = useListState({
    initialSelectedKeys: ['item1'],
    items: [
      { key: 'item1', name: 'Item 1' },
      { key: 'item2', name: 'Item 2' },
      { key: 'item3', name: 'Item 3' }
    ]
  });

  return (
    <ul>
      {state.collection.map(item => (
        <li key={item.key}>{item.name}</li>
      ))}
    </ul>
  );
}

useToggleState

The useToggleState hook manages the state for a toggleable component, such as a checkbox or switch. This example shows how to create a button that toggles between 'Selected' and 'Not Selected' states.

import { useToggleState } from 'react-stately';

function MyToggleComponent() {
  let state = useToggleState();

  return (
    <button onClick={state.toggle}>
      {state.isSelected ? 'Selected' : 'Not Selected'}
    </button>
  );
}

useComboBoxState

The useComboBoxState hook manages the state for a combo box component, including input value and item selection. This example demonstrates how to create a combo box with a list of items.

import { useComboBoxState } from 'react-stately';

function MyComboBoxComponent(props) {
  let state = useComboBoxState({
    items: [
      { key: 'item1', name: 'Item 1' },
      { key: 'item2', name: 'Item 2' },
      { key: 'item3', name: 'Item 3' }
    ]
  });

  return (
    <div>
      <input
        value={state.inputValue}
        onChange={e => state.setInputValue(e.target.value)}
      />
      <ul>
        {state.collection.map(item => (
          <li key={item.key}>{item.name}</li>
        ))}
      </ul>
    </div>
  );
}

Other packages similar to react-stately

FAQs

Package last updated on 28 Apr 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

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc