Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

use-array-state

azmenak247MIT1.0.2TypeScript support: included

Provides a reducer to simplify handling of mutations to array state

react, hook, hooks, async, reducer, typescript, esm, pika, useArrayState, useReducer

readme

use-array-state

A simple helper to makes changes to an array without needing to worry about mutating the value

Install

npm install use-array-state

Useage

import useArrayState from 'use-array-state'

function ArrayComponent () {
  const [value, valueActions] = useArrayState()

  return (
    <div>
      <button onClick={() => {valueActions.push('new-value')}}
      <pre>
        {JSON.stringify(value, null, 2)}
      </pre>
    </div>
  )
}

Available actions

See src/index.ts for the the interface, all methods contain docs in types