Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how can I put a logic in map array method. I have sent title as props and except props title I want to render other title

This is my code. When I use map method it maps every title in dummy data

Here, when I click bitcoin. Parent component sends bitcoin as title. I don't want to include bitcoin in the select tag.
Here, when I click bitcoin. Parent component sends bitcoin as title. I don’t want to include bitcoin in the select tag.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are returning the option directly from your map function, if you want to add logic inside just add {} and a return statement inside

{coins.map((item) => {
    // you can put your logic here
    // for example just first 2 letters
    const customTitle = item.title.slice(0, 2)
    return (
        <option>{customTitle}</option>
    )
})}

You can read more about arrow functions here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading