質問編集履歴

1

情報の追加

2021/10/23 12:58

投稿

tanana_m
tanana_m

スコア28

test CHANGED
File without changes
test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
 
4
4
 
5
- https://github.com/vercel/swr/blob/master/src/types.ts#L6-L32
5
+ [https://github.com/vercel/swr/blob/master/src/types.ts#L6-L32](https://github.com/vercel/swr/blob/master/src/types.ts#L6-L32)
6
6
 
7
7
 
8
8
 
@@ -77,3 +77,79 @@
77
77
  ご教示いただけると大変助かります。
78
78
 
79
79
  よろしくお願いいたします。
80
+
81
+
82
+
83
+ ## useSWRの定義
84
+
85
+
86
+
87
+ 追っていくと以下にあたります。
88
+
89
+ [https://github.com/vercel/swr/blob/da33f52633ef5bb357e074de8499c76661e23c78/src/use-swr.ts#L512](https://github.com/vercel/swr/blob/da33f52633ef5bb357e074de8499c76661e23c78/src/use-swr.ts#L512)
90
+
91
+
92
+
93
+ `withArgs`自体の定義は以下です。
94
+
95
+
96
+
97
+ [https://github.com/vercel/swr/blob/da33f52633ef5bb357e074de8499c76661e23c78/src/utils/resolve-args.ts#L11-L36](https://github.com/vercel/swr/blob/da33f52633ef5bb357e074de8499c76661e23c78/src/utils/resolve-args.ts#L11-L36)
98
+
99
+
100
+
101
+ ```typescript
102
+
103
+ export const withArgs = <SWRType>(hook: any) => {
104
+
105
+ return (((...args: any) => {
106
+
107
+ // Normalize arguments.
108
+
109
+ const [key, fn, _config] = normalize<any, any>(args)
110
+
111
+
112
+
113
+ // Get the default and inherited configuration.
114
+
115
+ const fallbackConfig = mergeObjects(
116
+
117
+ defaultConfig,
118
+
119
+ useContext(SWRConfigContext)
120
+
121
+ )
122
+
123
+
124
+
125
+ // Merge configurations.
126
+
127
+ const config = mergeConfigs(fallbackConfig, _config)
128
+
129
+
130
+
131
+ // Apply middleware
132
+
133
+ let next = hook
134
+
135
+ const { use } = config
136
+
137
+ if (use) {
138
+
139
+ for (let i = use.length; i-- > 0; ) {
140
+
141
+ next = use[i](next)
142
+
143
+ }
144
+
145
+ }
146
+
147
+
148
+
149
+ return next(key, fn || config.fetcher, config)
150
+
151
+ }) as unknown) as SWRType
152
+
153
+ }
154
+
155
+ ```