Return list from component Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Return list from component without wasting too much if your time.

The question is published on by Tutorial Guruji team.

One of my components creates a list of strings with random size (say 4~10 strings) everytime it is called.

Suppose the list is ["airplane", "ball", "car", "dice"].

I want to return a html structure that looks like this:

airplane   [button]
ball       [button]
car        [button]
dice       [button]

How can I do that? I don’t know how to return a dynamic size thing.

Answer

you’d better use the React Fragments and don’t forget about unique keys

<>
  {nameOfList.map(item => <span key={item}>{item} </span>)}
</>
We are here to answer your question about Return list from component - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji