2

I am trying to solve this problem almost for 1 day. I considered every possible solution, have been searching for a long time, but really have no idea what's wrong.

I need to make table with ant design and on initial rendering all the users should be displayed. I am using React / TypeScript, Axios and Zustand for state management. The problem is, that everything was working perfectly, I fetched data and it was working, but then out of nowhere I got that error "uncaught TypeError: rawData.some is not a function".

my Store.tsx

My Table component:

import {Table} from "antd";
import userStore from "./Store/Store";
import { useEffect} from "react";

const usersTable = () => {
  const { users, loading, error, fetchUsers} = userStore();

  useEffect(()=>{
    fetchUsers();
 }, [])

  const columns = [
    {
      title: 'Name',
      dataIndex: 'name',
      key: 'name',
    },
    {
      title: 'Email',
      dataIndex: 'email',
      key: 'email',
    },
    {
      title: 'Gender',
      dataIndex: 'gender',
      key: 'gender',
    },
    {
      title: 'Street',
      dataIndex: ['address', 'street'],
      key: 'street',
    },
    {
      title: 'City',
      dataIndex: ['address', 'city'],
      key: 'city',
    },
    {
      title: 'Phone',
      dataIndex: 'phone',
      key: 'phone',
    },
  ];

if (loading) {
    return <div>Loading...</div>;
  }

  if (error) {
    return <div>Error: {error.message}</div>;
  }
  
  return (
    <>
    <Table dataSource={users} columns={columns}/>
    </>
  )
}

export default usersTable

I checked everything in my code, I don't have explicitly defined rawData anywhere of course.

Wahlstrommm
  • 684
  • 2
  • 7
  • 21
  • 1
    antd `dataSource` props expects an array, and `some` is a method of the `array` object. Are you sure your API call is returning `array` as response ? – Junaed Siam May 06 '23 at 07:37

1 Answers1

0

I once had faced this similar issue and it was due to the following reason. It might be because you have defined an attribute in the table whose dataIndex does not exist. Please check the corresponding dataIndex of each attribute defined in the columns array and see if it matches the attribute names defined in table users.

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 08 '23 at 12:25