In previous episodes of react, we have learned how to pass props to the components. In this episode, we will see how could we pass the function as a prop to the child component.

Without wasting much time, let’s straight away take a deep dive into code:

At Line 10, we have created the function handleDeleteOptions, this function is being passed to the component of Options at Line 24.

Component Options looks like this —

--

--

In simple words,

ForEach allows you to iterate over the list of items.

Map function allows you to perform Iteration AND transform the items, you can choose whether you want to transform or do you just want to iterate.

Example —

ForEach in the below example is iterating over the list, If we would want to transform each item like ‘Hi Dog’, ‘Hi Cats!’, we would have to iterate like below, create another variable and assign the transformed value to it.

forEach example

If we choose to work with Map instead, it not only allows us to iterate but also to transform if we want.

--

--