Use Callbacks To Delete An Item#
Write The onDelete
Handler#
Now that we have our dummy handler ready, we need to add functionality to the handler.
Since the list of FAQ items is managed by our App
component, we cannot directly remove the item.
Rewrite the FaqItem
component so that both a unique identifier of the FAQ item and a callback to remove the FAQ item can be passed to this component.
Also complete the onDelete
handler such that it will call the callback with the correct identifier.
Write A Dummy Delete Handler#
Now we're ready to change the App
component to add a dummy onDelete
handler.
Add the onDelete
handler to the App
component, which logs the index of the FAQ item to the console.
Make sure to pass the index and the callback to the FaqItem
component to wire everything together:
Delete The FAQ Item From The List#
The last step is to remove the item from the list.
Write the onDelete
handler which removes the item from the list and creates the new state.