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

150
Visualizações
How to map through array inside the object in react.js?

enter image description here

I have tried

import React,{useState,useEffect} from 'react'
//import usestack from './Usestack'

export default function Table() {
    const [query, setQuery] = useState();
    const [finalq, setFinalq] = useState();
    const [pagenumber, setPagenumber] = useState(1);
    const [ques, setQues] = useState();
  
    async function apicall(finalq, pagenumber){
        var res = await fetch(`https://api.stackexchange.com/2.3/questions?page=${pagenumber}&order=desc&sort=activity&tagged=${finalq}&site=stackoverflow`)
        var data = await res.json();
        setQues(data)
    }

    const setq = (e)=>{
        setQuery(e.target.value);
    }

    const submitq=()=>{
        setFinalq(query);
        setQuery(' ');
        setPagenumber(1);
    }

    useEffect(() => {
        apicall(finalq,pagenumber);
    },[finalq, pagenumber])

    //console.log(ques); 

    return (
        <>
        <div>
            <input type='text' value={query} onChange={setq}/>    
            <button onClick={submitq}>Submit</button>
            <table>
                <tr>
                    <th>User id</th>
                    <th>User name</th>
                    <th>Quetion</th>
                </tr>
            </table>
            {ques.items.map((i,key)=>(
                <div>samruddh</div>
            ))}
        </div>
        </>
    )
}

but it is not working, it just makes react page plain white I have added the whole component and also so please check that.

I am fetching StackOverflow API with help of the input tag and button.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I just used your code in the below picture and it shows exact output on right side:

output

But as you said you seeing it just makes react page plain white so you need to use something like below to show the output on your react page.

<div>
{ 
  objectName.items.map((i, key)=>{
     <div>{i}</div>
  });
}
</div>
about 4 years ago · Juan Pablo Isaza Relatório
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