Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

accessorFn causes exception when state.isLoading is true and data is empty array #304

Closed
1 task done
cristiancundari opened this issue Apr 4, 2024 · 0 comments · Fixed by #308
Closed
1 task done
Labels
bug Something isn't working V1 Issue with MRT V1 V2 Issue with MRT V2

Comments

@cristiancundari
Copy link

mantine-react-table version

1.3.4 & v2

react & react-dom versions

17.0.2

Describe the bug and the steps to reproduce it

In a situation where the table data are fetched from a server; specifically, when the data array is still empty while awaiting the server response and the isLoading state is set to true to indicate that the data is not yet ready, an exception occurs if a columnDef employs an accessorFn to access a nested object property. This leads to application crash.

To replicate the problem, simply set the table data prop to an empty array, set the isLoading state to true, and utilize any columnDef that accesses a nested object property.

It appears that the accessorFn is invoked even when no data is present, causing row.name to be undefined.

Minimal, Reproducible Example - (Optional, but Recommended)

const columns = useMemo<MRT_ColumnDef<Person>[]>(
  () => [
    {
      accessorFn: (row) => row.name.firstName,
      id: 'firstName',
      header: 'First Name',
    },
  ],
  [],
);

const table = useMantineReactTable({
  columns,
  state: {
    isLoading: true
  },
  data: [], //must be memoized or stable (useState, useMemo, defined outside of this component, etc.)
});

Screenshots or Videos (Optional)

No response

Do you intend to try to help solve this bug with your own PR?

None

Terms

  • I understand that if my bug cannot be reliably reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working V1 Issue with MRT V1 V2 Issue with MRT V2
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants