Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into feature/angular-query
Browse files Browse the repository at this point in the history
  • Loading branch information
arnoud-dv committed Nov 28, 2023
2 parents c6eccc6 + f62e079 commit aa38cd6
Show file tree
Hide file tree
Showing 59 changed files with 2,774 additions and 660 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ env:
NX_CLOUD_DISTRIBUTED_EXECUTION_AGENT_COUNT: 3
NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }}
NX_CLOUD_AUTH_TOKEN: ${{ secrets.NX_CLOUD_AUTH_TOKEN }}
NX_VERBOSE_LOGGING: true

jobs:
main:
Expand Down Expand Up @@ -53,6 +54,7 @@ jobs:
max_attempts: 3
command: npx nx affected --targets=test:eslint,test:lib,test:types,test:build,test:bundle
- name: Stop Agents
if: ${{ always() }}
run: npx nx-cloud stop-all-agents
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
Expand Down
5 changes: 3 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ If you have been assigned to fix an issue or develop a new feature, please follo

- Fork this repository.
- Install dependencies by running `$ pnpm install`.
- We use [pnpm](https://pnpm.io/) v8 for package management.
- We use [nvm](https://github.com/nvm-sh/nvm) to manage node versions - please make sure to use the version mentioned in `.nvmrc`.
- We use [pnpm](https://pnpm.io/) v8 for package management (run `corepack enable && corepack prepare` in case of pnpm-related issues).
- We use [nvm](https://github.com/nvm-sh/nvm) to manage node versions - please make sure to use the version mentioned in `.nvmrc` (run `nvm use`).
- Build all packages using `pnpm build:all`.
- Run development server using `pnpm run watch`.
- Implement your changes and tests to files in the `src/` directory and corresponding test files.
- Document your changes in the appropriate doc page.
Expand Down
6 changes: 6 additions & 0 deletions docs/react/community/community-projects.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ Incrementally adoptable type-safety for your new and existing APIs

Link: https://ts-rest.com/

## wagmi

React Hooks for Ethereum based on `@tanstack/react-query`

Link: https://wagmi.sh/

## zodios

End-to-end typesafe REST API toolbox
Expand Down
2 changes: 1 addition & 1 deletion docs/react/guides/caching.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Let's assume we are using the default `gcTime` of **5 minutes** and the default
- When the request completes successfully, the cache's data under the `['todos']` key is updated with the new data, and both instances are updated with the new data.
- Both instances of the `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` query are unmounted and no longer in use.
- Since there are no more active instances of this query, a garbage collection timeout is set using `gcTime` to delete and garbage collect the query (defaults to **5 minutes**).
- Before the cache timeout has completed, another instance of `useQuery({ queryKey: ['todos'], queyFn: fetchTodos })` mounts. The query immediately returns the available cached data while the `fetchTodos` function is being run in the background. When it completes successfully, it will populate the cache with fresh data.
- Before the cache timeout has completed, another instance of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` mounts. The query immediately returns the available cached data while the `fetchTodos` function is being run in the background. When it completes successfully, it will populate the cache with fresh data.
- The final instance of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` unmounts.
- No more instances of `useQuery({ queryKey: ['todos'], queryFn: fetchTodos })` appear within **5 minutes**.
- The cached data under the `['todos']` key is deleted and garbage collected.
2 changes: 1 addition & 1 deletion docs/react/guides/dependent-queries.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const { data: userIds } = useQuery({
// Then get the users messages
const usersMessages = useQueries({
queries: userIds
? usersId.map((id) => {
? userIds.map((id) => {
return {
queryKey: ['messages', id],
queryFn: () => getMessagesByUsers(id),
Expand Down
4 changes: 2 additions & 2 deletions docs/react/guides/migrating-to-v5.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,15 +106,15 @@ To make the remove overloads migration easier, v5 comes with a codemod.
If you want to run it against `.js` or `.jsx` files, please use the command below:

```
npx jscodeshift ./path/to/src/ \
npx jscodeshift@latest ./path/to/src/ \
--extensions=js,jsx \
--transform=./node_modules/@tanstack/react-query/build/codemods/src/v5/remove-overloads/remove-overloads.js
```

If you want to run it against `.ts` or `.tsx` files, please use the command below:

```
npx jscodeshift ./path/to/src/ \
npx jscodeshift@latest ./path/to/src/ \
--extensions=ts,tsx \
--parser=tsx \
--transform=./node_modules/@tanstack/react-query/build/codemods/src/v5/remove-overloads/remove-overloads.js
Expand Down
2 changes: 0 additions & 2 deletions docs/react/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ You can install React Query via [NPM](https://npmjs.com/),
or a good ol' `<script>` via
[ESM.sh](https://esm.sh/).

> v5 is currently available as a release-candidate. We don't anticipate any major API changes from here on out. We encourage you to try it out and report any issues you find.
### NPM

```bash
Expand Down
6 changes: 6 additions & 0 deletions docs/vue/reference/useMutationState.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
id: useMutationState
title: useMutationState
ref: docs/react/reference/useMutationState.md
replace: { '@tanstack/react-query': '@tanstack/vue-query' }
---
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "react-vite",
"name": "react-vite4",
"private": true,
"type": "module",
"scripts": {
Expand All @@ -11,6 +11,6 @@
"@vitejs/plugin-react": "^4.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vite": "^4.5.0"
"vite": "^4.4.11"
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions integrations/react-vite5/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
11 changes: 11 additions & 0 deletions integrations/react-vite5/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<title>Vite + React</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
</body>
</html>
16 changes: 16 additions & 0 deletions integrations/react-vite5/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "react-vite5",
"private": true,
"type": "module",
"scripts": {
"test:bundle": "vite build"
},
"dependencies": {
"@tanstack/react-query": "workspace:*",
"@tanstack/react-query-devtools": "workspace:*",
"@vitejs/plugin-react": "^4.2.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"vite": "^5.0.2"
}
}
23 changes: 23 additions & 0 deletions integrations/react-vite5/src/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { useQuery } from '@tanstack/react-query'

export const App = () => {
const query = useQuery({
queryKey: ['test'],
queryFn: async () => {
await new Promise((r) => setTimeout(r, 1000))
return 'Success'
},
})

if (query.isPending) {
return <div>Loading...</div>
}

if (query.isError) {
return <div>An error has occurred!</div>
}

return <div>{query.data}</div>
}

export default App
18 changes: 18 additions & 0 deletions integrations/react-vite5/src/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import App from './App.jsx'

const queryClient = new QueryClient()

const root = ReactDOM.createRoot(document.getElementById('root'))

root.render(
<React.StrictMode>
<QueryClientProvider client={queryClient}>
<App />
<ReactQueryDevtools />
</QueryClientProvider>
</React.StrictMode>,
)
6 changes: 6 additions & 0 deletions integrations/react-vite5/vite.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
plugins: [react()],
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"test:ci": "nx run-many --exclude=examples/** --targets=test:format,test:sherif,test:eslint,test:lib,test:types,test:build,test:bundle,build",
"test:eslint": "nx affected --target=test:eslint",
"test:format": "pnpm run prettier --check",
"test:sherif": "sherif -i react-scripts -i typescript",
"test:sherif": "sherif -i react-scripts -i typescript --ignore-package react-vite5 --ignore-package react-vite4",
"test:lib": "nx affected --target=test:lib",
"test:lib:dev": "pnpm --filter \"./packages/**\" run test:lib:dev",
"test:build": "nx affected --target=test:build",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import * as React from 'react'
import { useQuery } from '@tanstack/react-query'

export const WithObjectPattern = () => {
const { isError, isLoading, isSuccess, status } = useQuery({
queryKey: ['queryKey'],
queryFn: () => ['data'],
})

if (isError || isLoading || isSuccess) {
console.log('Do something')
}

return <div>{JSON.stringify({ isError, isLoading, isSuccess, status })}</div>
}

export const WithObjectPatternAndRename = () => {
const { isError, isLoading: isLoadingRenamed, isSuccess, status } = useQuery({
queryKey: ['queryKey'],
queryFn: () => ['data'],
})

if (isError || isLoadingRenamed || isSuccess) {
console.log('Do something')
}

return <div>{JSON.stringify({ isError, isLoadingRenamed, isSuccess, status })}</div>
}

export const WithObjectPatternAndRestElement = () => {
const { isError, ...rest } = useQuery({
queryKey: ['queryKey'],
queryFn: () => ['data'],
})

if (isError || rest.isLoading || rest.isSuccess) {
console.log('Do something')
}

return <div>{JSON.stringify({ isError, isLoading: rest.isLoading, isSuccess: rest.isSuccess })}</div>
}

export const WithIdentifier = () => {
const queryResult = useQuery({
queryKey: ['queryKey'],
queryFn: () => ['data'],
})

if (queryResult.isError || queryResult.isLoading || queryResult.isSuccess) {
console.log('Do something')
}

return <div>{JSON.stringify(queryResult)}</div>
}

export const WithCombinations = () => {
function useSomethingElse() {
const { isError, isLoading, isSuccess, status } = useQuery({
queryKey: ['somethingElse'],
queryFn: () => ['data'],
})

return { isError, isLoading, isSuccess, status }
}

function useAnotherThing() {
const { isLoading, ...rest } = useQuery({
queryKey: ['anotherThing'],
queryFn: () => ['anotherData'],
})

return { isLoading: rest.isLoading, ...rest }
}

const { isError, isLoading: isLoadingRenamed, isSuccess, status } = useQuery({
queryKey: ['queryKey'],
queryFn: () => ['data'],
})

return isLoadingRenamed
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import * as React from 'react'
import { useQuery } from '@tanstack/react-query'

export const WithObjectPattern = () => {
const { isError, isPending, isSuccess, status } = useQuery({
queryKey: ['queryKey'],
queryFn: () => ['data'],
})

if (isError || isPending || isSuccess) {
console.log('Do something')
}

return <div>{JSON.stringify({ isError, isPending, isSuccess, status })}</div>;
}

export const WithObjectPatternAndRename = () => {
const { isError, isPending: isLoadingRenamed, isSuccess, status } = useQuery({
queryKey: ['queryKey'],
queryFn: () => ['data'],
})

if (isError || isLoadingRenamed || isSuccess) {
console.log('Do something')
}

return <div>{JSON.stringify({ isError, isLoadingRenamed, isSuccess, status })}</div>
}

export const WithObjectPatternAndRestElement = () => {
const { isError, ...rest } = useQuery({
queryKey: ['queryKey'],
queryFn: () => ['data'],
})

if (isError || rest.isPending || rest.isSuccess) {
console.log('Do something')
}

return <div>{JSON.stringify({ isError, isLoading: rest.isPending, isSuccess: rest.isSuccess })}</div>;
}

export const WithIdentifier = () => {
const queryResult = useQuery({
queryKey: ['queryKey'],
queryFn: () => ['data'],
})

if (queryResult.isError || queryResult.isPending || queryResult.isSuccess) {
console.log('Do something')
}

return <div>{JSON.stringify(queryResult)}</div>
}

export const WithCombinations = () => {
function useSomethingElse() {
const { isError, isPending, isSuccess, status } = useQuery({
queryKey: ['somethingElse'],
queryFn: () => ['data'],
})

return { isError, isPending, isSuccess, status };
}

function useAnotherThing() {
const { isPending, ...rest } = useQuery({
queryKey: ['anotherThing'],
queryFn: () => ['anotherData'],
})

return { isLoading: rest.isPending, ...rest };
}

const { isError, isPending: isLoadingRenamed, isSuccess, status } = useQuery({
queryKey: ['queryKey'],
queryFn: () => ['data'],
})

return isLoadingRenamed
}

Loading

0 comments on commit aa38cd6

Please sign in to comment.