pejay-ui 1.2.1 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/bin/cli.js +2 -2
  2. package/package.json +1 -1
  3. package/registry.json +39 -3
  4. package/templates/notes/create-pejay.md +222 -0
  5. package/templates/notes/notes-v1.md +516 -0
  6. package/templates/notes/notes-v2.md +764 -0
  7. package/templates/notes/notes-v3.md +574 -0
  8. package/templates/notes/notes-v4.md +811 -0
  9. package/templates/notes/notes-v5.md +579 -0
  10. package/templates/notes/notes-vf+1.md +311 -0
  11. package/templates/notes/notes-vfinal.md +852 -0
  12. package/templates/scaffolds/axios/api/index.ts +40 -0
  13. package/templates/scaffolds/axios/api/one.api.ts +94 -0
  14. package/templates/scaffolds/axios/endpoints.ts +9 -0
  15. package/templates/scaffolds/axios/index.ts +26 -0
  16. package/templates/scaffolds/axios/interceptors.ts +103 -0
  17. package/templates/scaffolds/axios/request.ts +32 -0
  18. package/templates/scaffolds/react-router/hook/useRouterSearch.ts +8 -0
  19. package/templates/scaffolds/react-router/router/guards/private.route.tsx +1 -0
  20. package/templates/scaffolds/react-router/router/index.ts +26 -0
  21. package/templates/scaffolds/react-router/router/layouts/error.layout.tsx +1 -1
  22. package/templates/scaffolds/redux-store/middlewares.ts +0 -0
  23. package/templates/scaffolds/redux-store/reducers.ts +30 -0
  24. package/templates/scaffolds/redux-store/selector/one.selector.ts +43 -0
  25. package/templates/scaffolds/redux-store/selector/two.selector.ts +11 -0
  26. package/templates/scaffolds/redux-store/slices/one.slice.ts +202 -0
  27. package/templates/scaffolds/redux-store/slices/two.slice.ts +21 -0
  28. package/templates/scaffolds/redux-store/store.ts +38 -0
  29. package/templates/scaffolds/rtk-query/baseApi.ts +24 -0
  30. package/templates/scaffolds/rtk-query/baseQuery.ts +12 -0
  31. package/templates/scaffolds/rtk-query/endpoints/api.one.ts +82 -0
  32. package/templates/scaffolds/rtk-query/endpoints/index.ts +1 -0
  33. package/templates/scaffolds/rtk-query/middlewares.ts +11 -0
  34. package/templates/scaffolds/rtk-query/queryTags.ts +13 -0
  35. package/templates/scaffolds/tanstack-query/api-base.ts +68 -68
  36. package/templates/scaffolds/tanstack-query/api-queries.ts +0 -19
  37. package/templates/scaffolds/tanstack-query/client.ts +8 -0
  38. package/templates/scaffolds/tanstack-query/module/index.ts +12 -12
  39. package/templates/scaffolds/tanstack-query/module/keys.ts +17 -17
  40. package/templates/scaffolds/tanstack-query/module/mappers.ts +15 -15
  41. package/templates/scaffolds/tanstack-query/module/mutations.ts +59 -55
  42. package/templates/scaffolds/tanstack-query/module/queries.ts +145 -156
  43. package/templates/scaffolds/tanstack-query/module/services.ts +74 -66
  44. package/templates/scaffolds/tanstack-router/layout/404.layout.tsx +3 -0
  45. package/templates/scaffolds/tanstack-router/layout/app.layout.tsx +10 -0
  46. package/templates/scaffolds/tanstack-router/layout/auth.layout.tsx +10 -0
  47. package/templates/scaffolds/tanstack-router/layout/error.layout.tsx +3 -0
  48. package/templates/scaffolds/tanstack-router/page/auth/login.tsx +3 -0
  49. package/templates/scaffolds/tanstack-router/page/one/index.tsx +3 -0
  50. package/templates/scaffolds/tanstack-router/page/one/one-id.tsx +128 -0
  51. package/templates/scaffolds/tanstack-router/router.ts +90 -0
  52. package/templates/scaffolds/tanstack-router/routes/_404.tsx +0 -0
  53. package/templates/scaffolds/tanstack-router/routes/__root.tsx +9 -0
  54. package/templates/scaffolds/tanstack-router/routes/_app.tsx +6 -0
  55. package/templates/scaffolds/tanstack-router/routes/_auth.tsx +6 -0
  56. package/templates/scaffolds/tanstack-router/routes/_error.tsx +0 -0
  57. package/templates/scaffolds/tanstack-router/routes/auth/login.tsx +6 -0
  58. package/templates/scaffolds/tanstack-router/routes/one/$id.tsx +191 -0
  59. package/templates/scaffolds/tanstack-router/routes/one/index.tsx +6 -0
  60. package/templates/scripts/setup.bat +284 -0
  61. package/templates/scripts/setup.ps1 +318 -0
@@ -0,0 +1,311 @@
1
+ # Understanding `loader()` + `Route.useLoaderData()` + `useSuspenseQuery()`
2
+
3
+ This is one of the most important concepts in TanStack Router.
4
+
5
+ A common misunderstanding is:
6
+
7
+ ```txt
8
+ "My component knows the ID.
9
+ How does the loader know which data to preload?"
10
+ ```
11
+
12
+ The answer is:
13
+
14
+ ```txt
15
+ The loader does NOT get information from the component.
16
+
17
+ The loader runs BEFORE the component is rendered.
18
+ ```
19
+
20
+ ---
21
+
22
+ # The Key Idea
23
+
24
+ When a URL is visited:
25
+
26
+ ```txt
27
+ /users/123
28
+ ```
29
+
30
+ TanStack Router already knows:
31
+
32
+ ```txt
33
+ Current Route
34
+ Current Params
35
+ Current Search Params
36
+ Router Context
37
+ ```
38
+
39
+ before any component mounts.
40
+
41
+ Because of that:
42
+
43
+ ```txt
44
+ Loader
45
+
46
+ already has access to params.id
47
+ ```
48
+
49
+ without needing anything from the page component.
50
+
51
+ ---
52
+
53
+ # Actual Request Flow
54
+
55
+ Suppose the user navigates to:
56
+
57
+ ```txt
58
+ /users/123
59
+ ```
60
+
61
+ TanStack Router performs the following steps:
62
+
63
+ ```txt
64
+ 1. Match Route
65
+
66
+
67
+ 2. Extract Route Params
68
+
69
+
70
+ 3. params.id = "123"
71
+
72
+
73
+ 4. Run Loader
74
+
75
+
76
+ 5. Loader Uses params.id
77
+
78
+
79
+ 6. Data Fetched
80
+
81
+
82
+ 7. Data Stored In Query Cache
83
+
84
+
85
+ 8. Component Mounts
86
+
87
+
88
+ 9. useSuspenseQuery Reads Cached Data
89
+ ```
90
+
91
+ The important thing to remember:
92
+
93
+ ```txt
94
+ The loader already knows the ID before the component exists.
95
+ ```
96
+
97
+ ---
98
+
99
+ # Why Is The ID Passed Again Inside useSuspenseQuery()?
100
+
101
+ A very common question:
102
+
103
+ ```txt
104
+ The loader already fetched user 123.
105
+
106
+ Why do I pass id again inside useSuspenseQuery()?
107
+ ```
108
+
109
+ Because TanStack Query identifies data using:
110
+
111
+ ```txt
112
+ queryKey
113
+ ```
114
+
115
+ Example:
116
+
117
+ ```txt
118
+ ["user", "123"]
119
+ ```
120
+
121
+ The loader:
122
+
123
+ ```txt
124
+ Fetches data
125
+ Stores it under a query key
126
+ ```
127
+
128
+ The component:
129
+
130
+ ```txt
131
+ Looks for that same query key
132
+ Reads the cached result
133
+ ```
134
+
135
+ The component is NOT making another request.
136
+
137
+ It is simply asking:
138
+
139
+ ```txt
140
+ "Do we already have data for user 123?"
141
+ ```
142
+
143
+ The answer is:
144
+
145
+ ```txt
146
+ Yes
147
+ ```
148
+
149
+ because the loader already populated the cache.
150
+
151
+ ---
152
+
153
+ # Mental Model
154
+
155
+ Think of the loader as:
156
+
157
+ ```txt
158
+ Loader
159
+
160
+ "Fetch user 123 and place it in cache."
161
+ ```
162
+
163
+ Think of the component as:
164
+
165
+ ```txt
166
+ Component
167
+
168
+ "Give me user 123 from cache."
169
+ ```
170
+
171
+ The component is not telling the loader what to fetch.
172
+
173
+ The loader already knew because:
174
+
175
+ ```txt
176
+ URL
177
+
178
+ Route Params
179
+
180
+ params.id
181
+ ```
182
+
183
+ were available before rendering started.
184
+
185
+ ---
186
+
187
+ # Important Distinction
188
+
189
+ Incorrect mental model:
190
+
191
+ ```txt
192
+ Component
193
+
194
+ Gets ID
195
+
196
+ Tells Loader What To Fetch
197
+ ```
198
+
199
+ This never happens.
200
+
201
+ ---
202
+
203
+ Correct mental model:
204
+
205
+ ```txt
206
+ URL
207
+
208
+ Route Match
209
+
210
+ Params Extracted
211
+
212
+ Loader Runs
213
+
214
+ Data Cached
215
+
216
+ Component Mounts
217
+
218
+ Component Reads Cache
219
+ ```
220
+
221
+ This is how TanStack Router actually works.
222
+
223
+ ---
224
+
225
+ # What Information Can A Loader Access?
226
+
227
+ A loader can access:
228
+
229
+ ```txt
230
+ Route Params
231
+
232
+ Search Params
233
+
234
+ Router Context
235
+
236
+ Current Location
237
+ ```
238
+
239
+ Examples:
240
+
241
+ ```txt
242
+ params.id
243
+
244
+ search.page
245
+
246
+ search.search
247
+
248
+ context.queryClient
249
+
250
+ context.auth
251
+
252
+ location.pathname
253
+ ```
254
+
255
+ This means loaders can make decisions and preload data before any page component renders.
256
+
257
+ ---
258
+
259
+ # Complete Lifecycle
260
+
261
+ The complete lifecycle for a typical detail page looks like:
262
+
263
+ ```txt
264
+ URL
265
+
266
+ Route Match
267
+
268
+ Extract Params
269
+
270
+ beforeLoad()
271
+
272
+ loader()
273
+
274
+ Fetch Data
275
+
276
+ Populate Query Cache
277
+
278
+ pendingComponent (if needed)
279
+
280
+ Component Mounts
281
+
282
+ useSuspenseQuery()
283
+
284
+ Reads Cached Data
285
+
286
+ UI Renders
287
+ ```
288
+
289
+ ---
290
+
291
+ # Final Rule To Remember
292
+
293
+ ```txt
294
+ Loader Fetches Data
295
+
296
+ Component Reads Data
297
+ ```
298
+
299
+ or
300
+
301
+ ```txt
302
+ Loader
303
+
304
+ Populate Cache
305
+
306
+ Component
307
+
308
+ Consume Cache
309
+ ```
310
+
311
+ Once this mental model clicks, TanStack Router + TanStack Query becomes much easier to reason about.