[Feature] Add useList hook with remove and removeAt functions#36147
Open
usmonovshohruxmirzo wants to merge 2 commits intofacebook:mainfrom
Open
[Feature] Add useList hook with remove and removeAt functions#36147usmonovshohruxmirzo wants to merge 2 commits intofacebook:mainfrom
usmonovshohruxmirzo wants to merge 2 commits intofacebook:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds a new
useListhook to simplify list management in React components.It provides a convenient way to remove items by condition or by index while automatically triggering re-renders.
Motivation
Currently, developers need to manually use
filterorspliceto remove items from arrays in React, which is repetitive and error-prone.useListoffers a unified abstraction to simplify these operations.Features
remove(predicate)— Removes items that match the given condition.removeAt(index)— Removes the item at the specified index.setList(newList)— Replaces the entire list.Example Usage
Test Coverage
setListremovefor partial match, no match, and full matchremoveAtfor valid index, invalid index, and empty listCloses #36005