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

@react-aria/collections

Package Overview
Dependencies
Maintainers
2
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-aria/collections

Spectrum UI components in React

  • 3.0.0-alpha.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
2
Created

What is @react-aria/collections?

@react-aria/collections is a library that provides utilities for managing collections of items in React applications. It is part of the React Aria suite, which offers a set of hooks and components for building accessible user interfaces. This package helps with managing state and rendering lists, grids, and other collections of items.

What are @react-aria/collections's main functionalities?

useCollection

The `useCollection` hook helps manage a collection of items. It takes an array of items and a function to get the key for each item. The hook returns a collection that can be mapped over to render the items.

import { useCollection } from '@react-aria/collections';

const items = [
  { id: 1, name: 'Item 1' },
  { id: 2, name: 'Item 2' },
  { id: 3, name: 'Item 3' }
];

function MyComponent() {
  const { collection } = useCollection({
    items,
    getKey: (item) => item.id
  });

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

useListState

The `useListState` hook manages the state of a list of items. It takes an array of items and a function to get the key for each item. The hook returns a state object that includes the collection of items, which can be used to render the list.

import { useListState } from '@react-aria/collections';

const items = [
  { id: 1, name: 'Item 1' },
  { id: 2, name: 'Item 2' },
  { id: 3, name: 'Item 3' }
];

function MyComponent() {
  const state = useListState({
    items,
    getKey: (item) => item.id
  });

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

useGridState

The `useGridState` hook manages the state of a grid of items. It takes an array of items and a function to get the key for each item. The hook returns a state object that includes the collection of items, which can be used to render the grid.

import { useGridState } from '@react-aria/collections';

const items = [
  { id: 1, name: 'Item 1' },
  { id: 2, name: 'Item 2' },
  { id: 3, name: 'Item 3' }
];

function MyComponent() {
  const state = useGridState({
    items,
    getKey: (item) => item.id
  });

  return (
    <div role="grid">
      {state.collection.map(item => (
        <div role="row" key={item.id}>{item.name}</div>
      ))}
    </div>
  );
}

Other packages similar to @react-aria/collections

FAQs

Package last updated on 21 Nov 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