Import this in your client-side component
MyComponent.tsx
import { useArray } from "react-amazing-hooks";
Api | Description | Type | Return Type | Example |
---|---|---|---|---|
add | Function to add an element to the array. | item: T | void | add(newItem) |
clear | Function to remove all elements from the array. | void | void | clear() |
removeById | Function to remove an element by its id. | id: number | void | removeById(1) |
removeIndex | Function to remove an element by index. | index: number | void | removeIndex(0) |
replaceAtIndex | Function to replace an element at a specific index. | index: number, newItem: T | void | replaceAtIndex(0, newItem) |
replaceById | Function to replace an element by its id. | id: number, newItem: T | void | replaceById(1, newItem) |
shuffle | Function to shuffle the array randomly. | void | void | shuffle() |
ascendingSort | Function to sort the array in ascending order. | void | void | ascendingSort() |
descendingSort | Function to sort the array in descending order. | void | void | descendingSort() |
Check the UseArrayReturn
and HasId
in the 'Types' tab.