Skip to content

Latest commit

Β 

History

History
44 lines (35 loc) Β· 605 Bytes

useArray.md

File metadata and controls

44 lines (35 loc) Β· 605 Bytes

πŸ₯Ÿ useArray

Manipulate and read an Array

Arguments

  • initialValue: Array: init of array

Returns

{
  add,
  clear,
  removeIndex,
  removeById,
  value,
  setValue
}

Usage

import { useArray } from 'react-recipes';

function App {
  const {
    add,
    clear,
    removeIndex,
    removeById,
    value: currentArray
  } = useArray(['cat','dog','bird']);

  return (
    <>
      <button onClick={() => add('tiger')}>Add animal</button>
      <button onClick={() => removeIndex(2)}>Remove Bird</button>
      <button onClick={clear}>Clear</button>
    </>
  )
};