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

168
Views
Why react map function is not working properly?

when I use the map in react, do I get an unexpected token error?

import React, { useState, useEffect } from "react";
import axios from "axios";

export default function ApiHook() {
  const [employees, setEmployees] = useState([]);

  useEffect(() => {
    axios
      .get("http://dummy.restapiexample.com/api/v1/employees")
      .then((response) => {
        console.log(response);
        setEmployees(response.data);
      })
      .catch((e) => console.log(e));
  }, []);
  return (
      {employees.map((employee) => {
        return <p>{employee.employee_name}</p>;
      })}
  );
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have to wrap with a fragment. Because you have to return only one element.

 return (
    <>
      {employees.map((employee) => {
        return <p>{employee.employee_name}</p>;
      })}
    </>
  );
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!