2021年4月28日星期三

react - × TypeError: users.map is not a function

I'm trying to do a get in my api that returns only one user, that in this user will have one of the tasks related to the user. This is an example of my interface.

interface IUsers {    id: string;    name: string;    tasks: {      id: string;      title: string;      description: string;      priority: string;      name_project: string;      date: Date;    };  

example of the code, in which I am trying to search for users, in the console.log it is shown that the user is returning me, but to render on the screen, the error occurs that .map is not a function

  const { user, signOut } = useAuth();      const [users, setUsers] = useState<IUsers[]>([]);      const getUser = useCallback(async () => {      const response = await api.get(`/users/${user.id}`);      console.log(response.data);      setUsers(response.data);    }, [user.id]);      useEffect(() => {      getUser();    }, [getUser]);  

And this is the way I'm trying to render the information on the screen.

<Container>        {users.map((users) => (          <Main key={users.id}>  ....  

result from console.log

{id: "9f389cd1-4c1d-4fe9-840a-2a513984aea6", name: "Wesley Israel", email: "wesleyteste@gmail.com", password: "$2a$08$PrV.UZ9LXe0IMQQZ0qw6ruNt28mj7rcOIUtxt1S1PQiOjjR03qA46", created_at: "2021-04-27T11:49:09.510Z", …}  created_at: "2021-04-27T11:49:09.510Z"  email: "wesleyteste@gmail.com"  id: "9f389cd1-4c1d-4fe9-840a-2a513984aea6"  name: "Wesley Israel"  password: "$2a$08$PrV.UZ9LXe0IMQQZ0qw6ruNt28mj7rcOIUtxt1S1PQiOjjR03qA46"  tasks: Array(1)  0: {id: "1ee527f1-dc28-4de2-a7dc-050505db034c", title: "Estudar Typescript", name_project: "University", user_id: "9f389cd1-4c1d-4fe9-840a-2a513984aea6", status: "NEW", …}  length: 1  __proto__: Array(0)  updated_at: "2021-04-27T11:49:09.510Z"  __proto__: Object  
https://stackoverflow.com/questions/67309991/react-%c3%97-typeerror-users-map-is-not-a-function April 29, 2021 at 09:44AM

没有评论:

发表评论