Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

147
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda