# I am getting error in react when i use npm run build - Step 40

**URL:** <https://forum.freecodecamp.org/t/i-am-getting-error-in-react-when-i-use-npm-run-build-step-40/682178>\
**Category:** Curriculum Help\
**Tags:** javascript\
**Created:** [March 26, 2024, 5:50am UTC](https://forum.freecodecamp.org/t/i-am-getting-error-in-react-when-i-use-npm-run-build-step-40/682178 "2024-03-26T05:50:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![akhila2](https://avatars.discourse-cdn.com/v4/letter/a/94ad74/32.png) [@akhila2](https://forum.freecodecamp.org/u/akhila2)\
**Post date:** [March 26, 2024, 5:50am UTC](https://forum.freecodecamp.org/t/i-am-getting-error-in-react-when-i-use-npm-run-build-step-40/682178/1 "2024-03-26T05:50:03Z")

</div>

### Tell us what’s happening:

in react when i use run build it goting this error

```plaintext
 TypeError: l.map is not a function
    at _n (AllPatientsTable.js:51:18)
    at Eo (react-dom.production.min.js:167:137)
    at Pi (react-dom.production.min.js:197:258)
    at Eu (react-dom.production.min.js:292:88)

```

but this is running in npm start  
what i have to do now

```jsx
import React, { useState, useEffect } from 'react';
import axios from 'axios';

const AllPatientsTable = () => {
  const [patients, setPatients] = useState([]);
  const [filteredPatients, setFilteredPatients] = useState([]);
  const [doctors, setDoctors] = useState([]);
  const [selectedDoctor, setSelectedDoctor] = useState('');

  useEffect(() => {
    fetchPatients();
    fetchDoctors();
  }, []);

  const fetchPatients = () => {
    axios.get('/patients')
      .then(response => {
        console.log(response.data)
        setPatients(response.data);
        setFilteredPatients(response.data);
      })
      .catch(error => console.error('Error fetching patients:', error));
  };

  const fetchDoctors = () => {
    axios.get('/doctors')
      .then(response => {
        setDoctors(response.data);
      })
      .catch(error => console.error('Error fetching doctors:', error));
  };

  const handleDoctorChange = (event) => {
    const selectedDoctorId = event.target.value;
    setSelectedDoctor(selectedDoctorId);
    if (selectedDoctorId === '') {
      setFilteredPatients(patients);
      
    } else {
      const filtered = patients.filter(patient => patient.doctor && patient.doctor.id === parseInt(selectedDoctorId));
      setFilteredPatients(filtered);
    }
  };

  return (
    <div>
      {/* <h3>Home </h3> */}
      <label htmlFor="doctor">Select a Doctor:</label>
      <select id="doctor" onChange={handleDoctorChange} value={selectedDoctor}>
        <option value="">All Doctors</option>
        {doctors.map(doctor => (
          <option key={doctor.id} value={doctor.id}>{doctor.name}</option>
        ))}
      </select>
      {filteredPatients.length === 0 ? (
        <p>No patients have been assigned to this doctor.</p>
      ) : (
      <table>
        <thead>
          <tr>
            <th>Name</th>
            <th>Weight</th>
            <th>Gender</th>
            <th>Age</th>
            <th>Disease</th>
            <th>Assigned Doctor</th>
          </tr>
        </thead>
        <tbody>
          {filteredPatients.map(patient => (
            <tr key={patient.id}>
              <td>{patient.name}</td>
              <td>{patient.weight}</td>
              <td>{patient.gender}</td>
              <td>{patient.age}</td>
              <td>{patient.disease}</td>
              <td>{patient.doctor ? patient.doctor.name : 'Not Assigned'}</td>
            </tr>
          ))}
        </tbody>
      </table>
       )}
    </div>
  );
};

export default AllPatientsTable;

```

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [March 26, 2024, 9:04am UTC](https://forum.freecodecamp.org/t/i-am-getting-error-in-react-when-i-use-npm-run-build-step-40/682178/2 "2024-03-26T09:04:58Z")

</div>

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (`</>`) to add backticks around text.

 ![Pre-formatted-text](https://global.discourse-cdn.com/freecodecamp/original/3X/1/b/1b18854f1059217f29370444396145cc3a0cd8ae.gif)

See [this post](https://forum.freecodecamp.org/t/forum-code-formatting/25574) to find the backtick on your keyboard.  
**Note:** Backticks (`) are not single quotes (').

---

<div class="post-metadata">

**Author:** ![lasjorg](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/lasjorg/32/280761_2.png) [@lasjorg](https://forum.freecodecamp.org/u/lasjorg)\
**Post date:** [March 26, 2024, 8:20pm UTC](https://forum.freecodecamp.org/t/i-am-getting-error-in-react-when-i-use-npm-run-build-step-40/682178/3 "2024-03-26T20:20:12Z")

</div>

I assume you mean the production build throws that error when you run it, not that it throws that error building the production build.

What does the API fetch log out in production?

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/freecodecamp/original/3X/e/1/e1c433102e34b46dfaa3e15d13ab9a514b127078.svg) [@system](https://forum.freecodecamp.org/u/system)\
**Post date:** [September 25, 2024, 8:21am UTC](https://forum.freecodecamp.org/t/i-am-getting-error-in-react-when-i-use-npm-run-build-step-40/682178/4 "2024-09-25T08:21:09Z")

</div>

Closed on September 25, 2024, 8:21am UTC

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.
