Skip to content

How to refresh the data in the InfiniteScroll component when I delete an item  #372

Open

Description

@mandula-abhilash

I am trying to delete an item from the component when I delete an Item. But it is not re rendering or refreshing the data.

Is this the default or expected behavior?

Is there a way to refresh the data without having to call the API again to re fetch the data?

Activity

  1. iamdarshshah commented on Apr 12, 2026

    @iamdarshshah
    Collaborator

    InfiniteScroll is a scroll container, it does not manage your data. It renders whatever children you pass in. When you delete an item, update your data array in state and re-render the list, the component will reflect the change automatically.

    const [items, setItems] = useState(initialItems);
    
    const handleDelete = (id) => {
      setItems(prev => prev.filter(item => item.id !== id));
    };
    
    <InfiniteScroll dataLength={items.length} ...>
      {items.map(item => <Item key={item.id} onDelete={handleDelete} />)}
    </InfiniteScroll>

    No API re-fetch needed, just update your local state. Does that help? Happy to answer follow-up questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions