'How to delete a list item from ant design List?

I want to show a list of data in ant design List.

enter image description here

I also want to add a delete or remove button at the end of the each list item. I am unable to find any API for adding this. I am using 4.3.5 version of antd from npm.

Is there any solution for this problem?



Solution 1:[1]

If you check the API for List.Item there is a prop called extra which accepts JSX and you can add the buttons their. For eg:

<List
    size="large"
    header={<div>Header</div>}
    footer={<div>Footer</div>}
    bordered
    dataSource={data}
    renderItem={(item) => (
      <List.Item extra={<Button size="small">Delete</Button>}>
        {item}
      </List.Item>
    )}
/>

You can also check working demo here: https://codesandbox.io/s/polished-fast-hzl9m?file=/index.js:477-755

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Yash Joshi