Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

i am fetching data and i am getting weird errors and i cant find the bug in it

i am fetching data and i am getting weird errors and i cant find the bug in it.
I tried every possible way can anyone help me

MultipleReturns.js:6 Uncaught TypeError: (0 , react__WEBPACK_IMPORTED_MODULE_0__.usestate) is not a function or its return value is not iterable

import React, { usestate, useEffect } from "react";

const url = "https://jsonplaceholder.typicode.com/posts";

const MultipleReturns = () => {
  const [isLoading, setLoading] = usestate(true);
  const [isError, setIsError] = usestate(false);
  const [user, setUser] = usestate("Default user");

  useEffect(() => {
    fetch(url)
      .then((resp) => {
        resp.json();
      })
      .then((user) => {
        const { login } = user;
        setUser(login);
        setLoading(false);
      })
      .catch((err) => {
        setIsError(err);
      });
  });
  if (isLoading) {
    return (
      <div>
        <h4>....Loading</h4>
      </div>
    );
  }

  if (isError) {
    return (
      <div>
        <h4>....Error</h4>
      </div>
    );
  }

  return (
    <>
      <div>MultipleReturns</div>
      <h4>{user}</h4>
    </>
  );
};

export default MultipleReturns;

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just a case of spelling, the state hook is called useState not usestate

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading