fetch("htt" /> fetch("htt" /> fetch("htt"/>

Class constructor Async cannot be invoked without 'new'

44 views Asked by At

I'm currently in my App.js file of my create-react-app project. Here's my code:

import useAsync from "react-async";

const loadUsers = () =>
  fetch("https://localhost:7088/api/reportdata/tenantmetric?requestDate=6%2F20%2f2023")
    .then((res) => (res.ok ? res : Promise.reject(res)))
    .then((res) => res.json());

const App = () => {
  const { data, error, isPending } = useAsync({ promiseFn: loadUsers, userId: 1 });
  if (isPending) return "Loading...";
  if (error) return `Something went wrong: ${error.message}`;
  if (data) {
    return (
      <div>
        <h2>React Async - Users</h2>
        {data.map((el) => (
          <li>
            {el.name} --- {el.email}
          </li>
        ))}
      </div>
    );
    return null;
  }
};
export default App;

When this code attempts to render I get hit with this error

Class constructor Async cannot be invoked without 'new'
TypeError: Class constructor Async cannot be invoked without 'new'`

What's going on here?

I tried added to right before useAsync on line 9 but that didn't work

0

There are 0 answers