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

124
Visualizações
How to get data of specific selected item

I am using external API of getting my data, that I fetch with axios.

I am able to receive data and map through them without any issues, but I need to be able to click on specific item from data and go to another page, that shows detailed data of that specific click item

(you can imagine it as blog that has blog posts and when you click on individual post, you get data only related to that post)

This is how I fetch my items in parent component:

 const [items, setItems] = useState([]);

    useEffect(() => {
        const getItems = async () => {
            try {
                const response = await axios.get(
                    'APIendpoint'
                );
                console.log(response);
                const final = response.data;
                setItems(final);
            } catch (error) {
                console.log(error);
            }
        };
        getItems();
    }, []);

And just mapping through them, with Link to another page:

 {items && items.map((item) => (
                        <div key={item.id}>
                            <Link to={`/closet/${item.id}`}>{item.name}</Link>
                        </div>
 ))}

And my router, which works and url does update:

<Route exact path="/"><App /></Route>
<Route exact path="/:id"><Component items={items}/></Route>

Now in Component.jsx I tried to do something like this:

const Main = ({ items }) => {

 useEffect(() => {
        const getDetail = async () => {
            try {
                const response = await axios.get(
                    `APIendpoint/${closetItems.id}` // path to the id 
                );
                console.log(response);
                const detail = response.data;
                setClosetItems(detail);
            } catch (error) {
                console.log(error);
            }
        };
        getDetail();
    }, []);

But nothing is happening when I console.log(closetItems) - I am not familiar with it, am I on right path or do I have to change the strategy?

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