Loading homepage
Implement a real React hook that manages an array of items and provides convenient methods for adding, filtering, replacing, removing, clearing, and resetting them. The JavaScript and TypeScript variants must expose the same interface.
The supplied tests render real React components, including a Strict Mode case. Updates must be visible after React rerenders, and batched operations must compose correctly.
Input: useArray([1, 2]); then push(3) Output: array is [1, 2, 3].
Input: useArray([1, 2, 3]); then filter((item) => item > 1) Output: array is [2, 3].
Input: useArray(['a', 'b']); then update(1, 'B'); then remove(0) Output: array is ['B'].
Input: useArray([1, 2]); then clear(); then reset() Output: array is [1, 2], using a fresh shallow copy of the mount-time snapshot.
Input: useArray([1]); then push(2); push(3) in one event Output: array is [1, 2, 3].
Returns the current array on each render and seven stable methods. Examples describe state after the corresponding React rerender.