@byndyusoft-ui/use-array
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

@byndyusoft-ui/use-array

Installation

npm i @byndyusoft-ui/use-array

Usage

import useArray from './useArray';

function MyComponent() {
    const [list, { append, prepend, update, remove, filter, sort, clear, reset }] = useArray<number>([1, 2, 3]);

    const handleAppend = () => append(4);
    const handleFilter = () => filter(item => item % 2 === 0);

    return (
        <div>
            <ul>
                {list.map(item => (
                    <li key={item}>{item}</li>
                ))}
            </ul>
            <button onClick={handleAppend}>Append</button>
            <button onClick={handleFilter}>Filter</button>
        </div>
    );
}

Properties and Functions

  • list: The current state of the array.
  • append(item): Adds an item to the end of the array.
  • prepend(item): Adds an item to the beginning of the array.
  • update(index, item): Update an item at a specific index.
  • remove(index): Update an item at a specific index.
  • filter(cb): Filters the array based on a provided callback function.
  • sort(cb): Sorts the array based on a provided callback function.
  • clear(): Clears all items from the array.
  • reset(): Resets the array to its initial value.

Package Sidebar

Install

npm i @byndyusoft-ui/use-array

Weekly Downloads

0

Version

0.0.1

License

Apache-2.0

Unpacked Size

4.87 kB

Total Files

7

Last publish

Collaborators

  • sadcitizen
  • alexanderbyndyu