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

148
Views
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 answers
Answer question

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 Report
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!