Skip to content

Commit de7f822

Browse files
committed
perf: use-request
1 parent aba2e5a commit de7f822

File tree

3 files changed

+47
-45
lines changed

3 files changed

+47
-45
lines changed

packages/hooks/docs/.vitepress/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default defineConfig({
140140
},
141141
{
142142
icon: 'discord',
143-
link: 'https://discord.gg/RU6ZPjf8',
143+
link: 'https://discord.gg/z5Ve5r9Kwp',
144144
},
145145
{
146146
icon: 'twitter',

packages/hooks/src/useRequest/docs/pluginDoc/demo/demo.vue

Lines changed: 44 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,54 +4,56 @@
44
</template>
55

66
<script lang="ts" setup>
7-
import { useRequest } from 'vue-hooks-plus'
7+
import { useRequest } from 'vue-hooks-plus'
88
9-
import { UseRequestPlugin } from '../../../types'
9+
import { UseRequestPlugin } from '../../../types'
1010
11-
interface FormatterDataType {
12-
name: string
13-
age: number
14-
}
11+
interface FormatterDataType {
12+
name: string
13+
age: number
14+
}
1515
16-
interface Formatter {
17-
(data?: FormatterDataType): { name: string; age: number }
18-
}
16+
interface CustomPluginFieldType {
17+
formatter: (data?: FormatterDataType) => { name: string; age: number }
18+
}
1919
20-
const useFormatterPlugin: UseRequestPlugin<
21-
FormatterDataType,
22-
[],
23-
{
24-
formatter: Formatter
25-
}
26-
> = (fetchInstance, { formatter }) => {
27-
return {
28-
onSuccess: () => {
29-
fetchInstance.setFetchState(formatter?.(fetchInstance.state.data), 'data')
30-
},
31-
}
20+
const useFormatterPlugin: UseRequestPlugin<
21+
FormatterDataType,
22+
[],
23+
{
24+
formatter: CustomPluginFieldType['formatter']
3225
}
33-
34-
function getUsername(): Promise<{ name: string; age: number }> {
35-
return new Promise(resolve => {
36-
setTimeout(() => {
37-
resolve({
38-
name: 'vue-hooks-plus',
39-
age: 18,
40-
})
41-
}, 1000)
42-
})
26+
> = (fetchInstance, { formatter }) => {
27+
return {
28+
onSuccess: () => {
29+
fetchInstance.setFetchState(formatter?.(fetchInstance.state.data), 'data')
30+
},
4331
}
32+
}
33+
34+
function getUsername(): Promise<{ name: string; age: number }> {
35+
return new Promise(resolve => {
36+
setTimeout(() => {
37+
resolve({
38+
name: 'vue-hooks-plus',
39+
age: 18,
40+
})
41+
}, 1000)
42+
})
43+
}
44+
45+
4446
45-
const { data, loading } = useRequest(
46-
() => getUsername(),
47-
{
48-
formatter: (params?: FormatterDataType) => {
49-
return {
50-
name: `${params?.name} - plugins update`,
51-
age: 20,
52-
}
53-
},
47+
const { data, loading } = useRequest(
48+
() => getUsername(),
49+
{
50+
formatter: (params?: FormatterDataType) => {
51+
return {
52+
name: `${params?.name} - plugins update`,
53+
age: 20
54+
}
5455
},
55-
[useFormatterPlugin],
56-
)
56+
},
57+
[useFormatterPlugin],
58+
)
5759
</script>

packages/hooks/src/useRequest/useRequest.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ function useRequest<
2323
PluginsOptions extends (infer P)[]
2424
? P extends UseRequestPlugin<TData, TParams, infer R>
2525
? R
26-
: any
27-
: any
26+
: never
27+
: never
2828
>,
2929
plugins?: PluginsOptions,
3030
) {

0 commit comments

Comments
 (0)