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

Incorrect 'mutation' comment statement in FAQ #5871

Open
rickvian opened this issue Jan 17, 2025 · 1 comment
Open

Incorrect 'mutation' comment statement in FAQ #5871

rickvian opened this issue Jan 17, 2025 · 1 comment

Comments

@rickvian
Copy link

in this link

https://tanstack.com/table/latest/docs/faq#pitfall-2-mutating-columns-or-data-in-place

export default function MyComponent() {
  //✅ GOOD
  const columns = useMemo(() => [
    // ...
  ], []);

  //✅ GOOD (React Query provides stable references to data automatically)
  const { data, isLoading } = useQuery({
    //...
  });

  const table = useReactTable({
    columns,
    //❌ BAD: This will cause an infinite loop of re-renders because `data` is mutated in place (destroys stable reference)
    data: data?.filter(d => d.isActive) ?? [],
  });

  return <table>...</table>;

Though it still cause infinite loop,
i find the statement is slightly incorrect since the .filter is not mutating the data,
in fact the data.filter is returning new array reference, not mutating it,

if it were mutated, it also wont change the array reference anway...

I think could have minor fix on that doc part

@rickvian
Copy link
Author

#5872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant