Question: Getting the same (state) undefined error across multiple components. I've checked and seen that data does come from the API, isn't blocked by CORS or something, and is available to the useEffect callback. The problem seems to be in setting the state. I tried replacing the useState hook with the useRef hook and got the same result when accessing ref.current.

What's really weird, is, a couple of days ago everything worked fine, so I moved to work on the backend code to be greated today with a white screen.

The error, the familiar:

**Uncaught TypeError: can't access property "map", data is undefined**

*Dashboard.tsx* the index route.

```
export default function Dashboard() {
  const [loading, setLoading] = useState(true);
  const [data, setData] = useState<ServiceStatus[]>([]);

  useEffect(() => {
    setLoading(true);
    server.monitor.services()
      .then(data => setData(data))
      .finally(() => setLoading(false));
  }, []);

  return (
    <div>
      <Title order={2}>Dashboard</Title>
      <BackToTop />
      <div>
        <LoadingOverlay visible={loading} overlayBlur={2} />
        {data
          .map(svc => <ServiceStatusListItem key={svc.value?.ServiceName} status={svc} />)}
      </div>
    </div>
  );
}

```

*server.ts*

```
export const server = {
  monitor: {
    services: async () => {
      const url = `${hostname}/Monitor/Services`;
      const statuses = await fetch(url, addAuthorization()).then(resp => resp.json());
      return statuses as ServiceStatus[];
    }
  }
};

```

Screenshots available at <https://imgur.com/a/Rbgi8Ba>.

Answer: 
So as a technically correct answer for a quick fix:

In each RaiseRequest() method, you can just pass `this` in to the Add-call like:

```
public class Department
{      
    public bool RaiseRequest()
    {
        return Helpdesk.DepQueue.Add(this);
    }
}

```

Although this would only put the department or employee itself into the queue, which might be or might not be enough for your concrete use case (which your question doesn't include, so I don't know). This would basically just say "This department/employee has a helpdesk request" and nothing more.

For the next bigger version that might help you more in the long run, look at Varun Gupta's answer.

For an even bigger answer, turn the answer of Varun Gupta around and do it the other way:

Make a `class Request<T>` which holds a reference to a T (maybe called requester or something), and also a `string RequestText` or something, and then have your Queue be `depQueue = new RequestQueue<Request<Department>` so you can put requests in there. Then you can have the `RaiseRequest` method create a new Request object each time, which includes the raising object (in that context, `this`), a request text, and possibly other things like a timestamp when it was created.
I think the implementation shown in the class diagram is incomplete and they want us to run our horses and add the properties for Employee and Department classes in the respective classes only on our own. That being said I have added a property called Request, initialized it by making a constructor in the class and then pass it as an actual parameter to the add method so it doesn't go as null. Below is the example shown only for Department class. We can perform the same for the Employee class as well.

```
public class Department
{
    public string Request { get; set; }
    public Department(string request)
    {
        this.Request = request;
    }

    public static bool RaiseRequest(Department depReq)
    {
        return Helpdesk.DepQueue.Add(depReq);
    }
}

```

MAIN:

```
static void Main(string[] args)
    {
        string Request1 = "Clicking error";
        Department department1 = new Department(Request1);
        if (Department.RaiseRequest(department1))
        {
            Console.WriteLine("1st Department request type ticket created");
        }

        string Request2 = ".jpeg error";
        Department department2 = new Department(Request2);                  
        if (Department.RaiseRequest(department2))
        {
            Console.WriteLine("2nd Department request type ticket created.");
        }

        string Request3 = "404 error";
        Department department3 = new Department(Request3);
        if (Department.RaiseRequest(department2))
        {
            Console.WriteLine("2nd Department request type ticket created.");
        }

        //fulfilling the first request
        if (Helpdesk.ProcessDepRequest())
        {
            Console.WriteLine("Department type Request 1 has been processed and fulfilled by Helpdesk!");
        }

    }

```