Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 56 additions & 5 deletions docs/eslint/exhaustive-deps.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,64 @@ const todoQueries = {
Examples of **correct** code for this rule:

```tsx
useQuery({
queryKey: ['todo', todoId],
queryFn: () => api.getTodo(todoId),
})
const Component = ({ todoId }) => {
const todos = useTodos()
useQuery({
queryKey: ['todo', todos, todoId],
queryFn: () => todos.getTodo(todoId),
})
}
```

```tsx
const todos = createTodos()
const todoQueries = {
detail: (id) => ({ queryKey: ['todo', id], queryFn: () => api.getTodo(id) }),
detail: (id) => ({
queryKey: ['todo', id],
queryFn: () => todos.getTodo(id),
}),
}
```

```tsx
// with { allowlist: { variables: ["todos"] }}
const Component = ({ todoId }) => {
const todos = useTodos()
useQuery({
queryKey: ['todo', todoId],
queryFn: () => todos.getTodo(todoId),
})
}
```

```tsx
// with { allowlist: { types: ["TodosClient"] }}
class TodosClient { ... }
const Component = ({ todoId }) => {
const todos: TodosClient = new TodosClient()
useQuery({
queryKey: ['todo', todoId],
queryFn: () => todos.getTodo(todoId),
})
}
```

### Options

- `allowlist.variables`: An array of variable names that should be ignored when checking dependencies
- `allowlist.types`: An array of TypeScript type names that should be ignored when checking dependencies

```json
{
"@tanstack/query/exhaustive-deps": [
"error",
{
"allowlist": {
"variables": ["api", "config"],
"types": ["ApiClient", "Config"]
}
}
]
}
```

Expand Down
2 changes: 1 addition & 1 deletion examples/angular/auto-refetching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@angular/compiler": "^20.0.0",
"@angular/core": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
6 changes: 3 additions & 3 deletions examples/angular/basic-persister/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
"@angular/compiler": "^20.0.0",
"@angular/core": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-persist-client": "^5.94.5",
"@tanstack/query-async-storage-persister": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"@tanstack/angular-query-persist-client": "^5.95.0",
"@tanstack/query-async-storage-persister": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@angular/compiler": "^20.0.0",
"@angular/core": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/devtools-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@angular/core": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@angular/router": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@angular/compiler": "^20.0.0",
"@angular/core": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/optimistic-updates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@angular/core": "^20.0.0",
"@angular/forms": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/pagination/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@angular/compiler": "^20.0.0",
"@angular/core": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/query-options-from-a-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@angular/core": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@angular/router": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/router/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@angular/core": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@angular/router": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/rxjs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"@angular/core": "^20.0.0",
"@angular/forms": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/angular/simple/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@angular/compiler": "^20.0.0",
"@angular/core": "^20.0.0",
"@angular/platform-browser": "^20.0.0",
"@tanstack/angular-query-experimental": "^5.94.5",
"@tanstack/angular-query-experimental": "^5.95.0",
"rxjs": "^7.8.2",
"tslib": "^2.8.1",
"zone.js": "0.15.0"
Expand Down
6 changes: 3 additions & 3 deletions examples/react/algolia/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
},
"dependencies": {
"@algolia/client-search": "5.2.1",
"@tanstack/react-query": "^5.94.5",
"@tanstack/react-query-devtools": "^5.94.5",
"@tanstack/react-query": "^5.95.0",
"@tanstack/react-query-devtools": "^5.95.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.94.5",
"@tanstack/eslint-plugin-query": "^5.95.0",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@vitejs/plugin-react": "^4.3.4",
Expand Down
3 changes: 2 additions & 1 deletion examples/react/algolia/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ import ReactDOM from 'react-dom/client'

import App from './App'

const rootElement = document.getElementById('root') as HTMLElement
const rootElement = document.getElementById('root')
if (!rootElement) throw new Error('Missing #root element')
ReactDOM.createRoot(rootElement).render(<App />)
4 changes: 2 additions & 2 deletions examples/react/auto-refetching/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"start": "next start"
},
"dependencies": {
"@tanstack/react-query": "^5.94.5",
"@tanstack/react-query-devtools": "^5.94.5",
"@tanstack/react-query": "^5.95.0",
"@tanstack/react-query-devtools": "^5.95.0",
"next": "^16.0.7",
"react": "^19.2.1",
"react-dom": "^19.2.1"
Expand Down
4 changes: 2 additions & 2 deletions examples/react/basic-graphql-request/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.94.5",
"@tanstack/react-query-devtools": "^5.94.5",
"@tanstack/react-query": "^5.95.0",
"@tanstack/react-query-devtools": "^5.95.0",
"graphql": "^16.9.0",
"graphql-request": "^7.1.2",
"react": "^19.0.0",
Expand Down
3 changes: 2 additions & 1 deletion examples/react/basic-graphql-request/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -172,5 +172,6 @@ function Post({
)
}

const rootElement = document.getElementById('root') as HTMLElement
const rootElement = document.getElementById('root')
if (!rootElement) throw new Error('Missing #root element')
ReactDOM.createRoot(rootElement).render(<App />)
10 changes: 5 additions & 5 deletions examples/react/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"test:eslint": "eslint ./src"
},
"dependencies": {
"@tanstack/query-async-storage-persister": "^5.94.5",
"@tanstack/react-query": "^5.94.5",
"@tanstack/react-query-devtools": "^5.94.5",
"@tanstack/react-query-persist-client": "^5.94.5",
"@tanstack/query-async-storage-persister": "^5.95.0",
"@tanstack/react-query": "^5.95.0",
"@tanstack/react-query-devtools": "^5.95.0",
"@tanstack/react-query-persist-client": "^5.95.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.94.5",
"@tanstack/eslint-plugin-query": "^5.95.0",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@vitejs/plugin-react": "^4.3.4",
Expand Down
4 changes: 2 additions & 2 deletions examples/react/chat/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.94.5",
"@tanstack/react-query-devtools": "^5.94.5",
"@tanstack/react-query": "^5.95.0",
"@tanstack/react-query-devtools": "^5.95.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
Expand Down
3 changes: 2 additions & 1 deletion examples/react/chat/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@ function Example() {
)
}

const rootElement = document.getElementById('root') as HTMLElement
const rootElement = document.getElementById('root')
if (!rootElement) throw new Error('Missing #root element')
ReactDOM.createRoot(rootElement).render(<App />)
4 changes: 2 additions & 2 deletions examples/react/default-query-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.94.5",
"@tanstack/react-query-devtools": "^5.94.5",
"@tanstack/react-query": "^5.95.0",
"@tanstack/react-query-devtools": "^5.95.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
Expand Down
3 changes: 2 additions & 1 deletion examples/react/default-query-function/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,6 @@ function Post({
)
}

const rootElement = document.getElementById('root') as HTMLElement
const rootElement = document.getElementById('root')
if (!rootElement) throw new Error('Missing #root element')
ReactDOM.createRoot(rootElement).render(<App />)
4 changes: 2 additions & 2 deletions examples/react/devtools-panel/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
"preview": "vite preview"
},
"dependencies": {
"@tanstack/react-query": "^5.94.5",
"@tanstack/react-query-devtools": "^5.94.5",
"@tanstack/react-query": "^5.95.0",
"@tanstack/react-query-devtools": "^5.95.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
Expand Down
3 changes: 2 additions & 1 deletion examples/react/devtools-panel/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,6 @@ function Example() {
)
}

const rootElement = document.getElementById('root') as HTMLElement
const rootElement = document.getElementById('root')
if (!rootElement) throw new Error('Missing #root element')
ReactDOM.createRoot(rootElement).render(<App />)
10 changes: 5 additions & 5 deletions examples/react/eslint-legacy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
"test:eslint": "ESLINT_USE_FLAT_CONFIG=false eslint ./src/**/*.tsx"
},
"dependencies": {
"@tanstack/query-async-storage-persister": "^5.94.5",
"@tanstack/react-query": "^5.94.5",
"@tanstack/react-query-devtools": "^5.94.5",
"@tanstack/react-query-persist-client": "^5.94.5",
"@tanstack/query-async-storage-persister": "^5.95.0",
"@tanstack/react-query": "^5.95.0",
"@tanstack/react-query-devtools": "^5.95.0",
"@tanstack/react-query-persist-client": "^5.95.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.94.5",
"@tanstack/eslint-plugin-query": "^5.95.0",
"@types/react": "^18.2.79",
"@types/react-dom": "^18.2.25",
"@vitejs/plugin-react": "^4.3.4",
Expand Down
3 changes: 2 additions & 1 deletion examples/react/eslint-legacy/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,5 +157,6 @@ function App() {
)
}

const rootElement = document.getElementById('root') as HTMLElement
const rootElement = document.getElementById('root')
if (!rootElement) throw new Error('Missing #root element')
ReactDOM.createRoot(rootElement).render(<App />)
21 changes: 21 additions & 0 deletions examples/react/eslint-plugin-demo/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import pluginQuery from '@tanstack/eslint-plugin-query'
import tseslint from 'typescript-eslint'

export default [
...tseslint.configs.recommended,
...pluginQuery.configs['flat/recommended'],
{
files: ['src/**/*.ts', 'src/**/*.tsx'],
rules: {
'@tanstack/query/exhaustive-deps': [
'error',
{
allowlist: {
variables: ['api'],
types: ['AnalyticsClient'],
},
},
],
},
},
]
27 changes: 27 additions & 0 deletions examples/react/eslint-plugin-demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "@tanstack/query-example-eslint-plugin-demo",
"private": true,
"type": "module",
"scripts": {
"test:eslint": "eslint ./src"
},
"dependencies": {
"@tanstack/react-query": "^5.95.0",
"react": "^19.0.0"
},
"devDependencies": {
"@tanstack/eslint-plugin-query": "^5.95.0",
"eslint": "^9.39.0",
"typescript": "5.8.3",
"typescript-eslint": "^8.48.0"
},
"nx": {
"targets": {
"test:eslint": {
"dependsOn": [
"^build"
]
}
}
}
}
Loading
Loading