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

[lint]: no-rest-destructuring only reports on inline destructuring #8747

Open
TkDodo opened this issue Mar 4, 2025 · 2 comments
Open

[lint]: no-rest-destructuring only reports on inline destructuring #8747

TkDodo opened this issue Mar 4, 2025 · 2 comments

Comments

@TkDodo
Copy link
Collaborator

TkDodo commented Mar 4, 2025

As shown in the docs, this correctly errors:

const useTodos = () => {
  const { data: todos, ...rest } = useQuery({
    queryKey: ['todos'],
    queryFn: () => api.getTodos(),
  })
  return { todos, ...rest }
}

but this does not:

const useTodos = () => {
  const query = useQuery({
    queryKey: ['todos'],
    queryFn: () => api.getTodos(),
  })
  return { ...rest, data: data[0] }
}

It would be great if any destucuring in the same scope could trigger the violation. Is that possible @Newbie012 ?

@Newbie012
Copy link
Collaborator

Did you mean any query destructing in the same scope?

const useTodos = () => {
  const query = useQuery({
    queryKey: ['todos'],
    queryFn: () => api.getTodos(),
  })
  return { ...query, data: query.data[0] }
}

@TkDodo
Copy link
Collaborator Author

TkDodo commented Mar 4, 2025

yes, exactly, sorry, I messed up the code example 🙈

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

No branches or pull requests

2 participants