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

275
Views
API.js:54 Uncaught (in promise) TypeError: this.state.data.map is not a function

React/JavaScript newbie here. Spent all day changing my API call so it displays a loading state so the page doesn't render API data that hasn't yet been called but all I'm getting is .map() is not a function.

Could anyone give me a few pointers plesae?

const Loader = () => (
  <div class="divLoader">
    <svg class="svgLoader" viewBox="0 0 100 100" width="10em" height="10em">
      //Loader animation
    </svg>
  </div>
);

class Sonos extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      loading: true,
      data: [],
    };
  }

//API is called
  componentDidMount() {
    axios.get("API_KEY").then((res) => {
      const data = res.data;
      this.setState({ data: [], loading: false });

     
    
     console.log(data);
      
    });
  }

  render() {
    return (
      <div>
        {this.state.loading ? <Loader /> : null}
        <table border="1">
          <parent>
            <div className=" text-gray-700  items-center text-3xl  ">
              <div className="bg-gradient-to-r from-green-400 to-blue-500  min-w-full min-h-full">
                <div className="text-4xl font-semibold">
                 {this.state.data.map((n) =>{
                   return (
                     <h1>pleasse</h1>

                   
                 
           
                   )
                 })}
                </div>
              
             
              </div>
            </div>
          </parent>
        </table>
      </div>
    );
  }
}

export { Sonos };
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

 render(){
   if(this.state.loading){
    return <Loader />
   }
    // return table if loading is false
    // handling error goes with the same logic
   // table will only render if loading is false
   return (
    <table>

    </table>
   )
 }
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!