Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
Take a specific value of a map array in reactJS

i am working with a REST API that provides data for different countries. I have a search box and when i am typing letters under the box appeared different countries that matches with the search. Each country that appears has a button beside and when you click that button some information about this country appears. I have two different components, the first component showing the countries that matches the search and the second component showing the information from the selected country.

The code of the first component:

import {useState} from 'react'
import TheCountry from './TheCountry'

const TheSearchCountry= ({countrie}) => {

 const [buttonClicked, setButtonClicked] = useState(true)

 return (
    buttonClicked ?
        countrie.map(country => (
            <p key={country.name}>
                {country.name}
                <button onClick={() => {setButtonClicked(false)}}>show</button>
            </p>
        ))
    : <TheCountry countries={countrie} />
  )
}

export default TheSearchCountry

The second component called

<TheCountry/>

When the user clicks the show button i want to call the component

<TheCountry/>

and show in the screen the details about this particular country. But something like this did not happen, i screen all the data for all the countries that matches the search query. I did not find a correct way to call my component and isolate the country that trigger the button. Can anyone help ?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!