Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

153
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda