-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(RQ): improve react-query plugin (#12226)
* example: add react-query v5 example * chore: extract flatted method * chore(RQ): extract RQ exports * feat(RQ): add runtime config and v5 compat types * chore: update lockfile * example: update RQ example * fix(RQ): cannot write empty tmp file * docs: update RQ doc
- Loading branch information
Showing
15 changed files
with
320 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export default { | ||
plugins: ['@umijs/plugins/dist/react-query'], | ||
reactQuery: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { RuntimeReactQueryType } from 'umi'; | ||
|
||
export const reactQuery: RuntimeReactQueryType = { | ||
queryClient: { | ||
defaultOptions: { | ||
queries: { | ||
refetchOnWindowFocus: false, | ||
}, | ||
}, | ||
}, | ||
devtool: { | ||
buttonPosition: 'bottom-left', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
{ | ||
"name": "@example/with-react-query-v5", | ||
"private": true, | ||
"scripts": { | ||
"build": "umi build", | ||
"dev": "umi dev", | ||
"start": "npm run dev" | ||
}, | ||
"dependencies": { | ||
"@tanstack/react-query": "^5.28.6", | ||
"@tanstack/react-query-devtools": "^5.28.6", | ||
"umi": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { useQuery } from 'umi'; | ||
import '../style.less'; | ||
|
||
export default function HomePage() { | ||
const { isFetching, data } = useQuery({ | ||
queryKey: ['repoData'], | ||
queryFn: () => { | ||
return new Promise<{ stargazers_count: number }>((resolve, _) => { | ||
setTimeout(async () => { | ||
const res = await fetch('https://api.github.com/repos/umijs/umi'); | ||
const json = await res.json(); | ||
resolve(json); | ||
}, 500); | ||
}); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div className="container"> | ||
<div> | ||
<p className="title">UmiJS x react-query v5</p> | ||
{isFetching ? ( | ||
<p>Loading ...</p> | ||
) : ( | ||
<p>UmiJS has {data?.stargazers_count} stars now!</p> | ||
)} | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# react-query-v5 | ||
|
||
An example of using [UmiJS](https://umijs.org/zh-CN) with [react-query](https://github.com/TanStack/query) v5. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
body { | ||
font-family: 'Lucida Sans', sans-serif; | ||
} | ||
|
||
.container { | ||
width: 100%; | ||
height: 100vh; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
|
||
div { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
} | ||
|
||
.title { | ||
font-size: 64px; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "./.umi/tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { RuntimeReactQueryType } from 'umi'; | ||
|
||
export const reactQuery: RuntimeReactQueryType = { | ||
queryClient: { | ||
defaultOptions: { | ||
queries: { | ||
refetchOnWindowFocus: false, | ||
}, | ||
}, | ||
}, | ||
devtool: { | ||
position: 'bottom-left', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "./.umi/tsconfig.json" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.