@hyper-fetch/react 8.1.1 → 8.2.2

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 (131) hide show
  1. package/README.md +202 -52
  2. package/__tests__/features/helpers/use-request-events/use-request-events.base.spec.ts +1 -1
  3. package/__tests__/features/helpers/use-request-events/use-request-events.utils.spec.ts +1 -1
  4. package/__tests__/features/helpers/use-socket-state/use-socket-state.base.spec.ts +3 -3
  5. package/__tests__/features/helpers/use-tracked-state/use-tacked-state.actions.spec.ts +1 -1
  6. package/__tests__/features/helpers/use-tracked-state/use-tracked-state.base.spec.ts +55 -55
  7. package/__tests__/features/helpers/use-tracked-state/use-tracked-state.utils.spec.ts +8 -9
  8. package/__tests__/features/provider/provider.hydration.spec.tsx +3 -4
  9. package/__tests__/features/provider/use-config-provider.base.spec.tsx +1 -2
  10. package/__tests__/features/use-app-manager/use-app-manager.base.spec.ts +1 -1
  11. package/__tests__/features/use-cache/use-cache.base.spec.ts +6 -6
  12. package/__tests__/features/use-cache/use-cache.typescript.spec.ts +1 -2
  13. package/__tests__/features/use-emitter/use-emitter.base.spec.ts +1 -1
  14. package/__tests__/features/use-fetch/use-fetch.base.spec.ts +13 -9
  15. package/__tests__/features/use-fetch/use-fetch.cancel.spec.ts +1 -1
  16. package/__tests__/features/use-fetch/use-fetch.clear-state.spec.ts +1 -1
  17. package/__tests__/features/use-fetch/use-fetch.concurrency.spec.ts +1 -1
  18. package/__tests__/features/use-fetch/use-fetch.debounce.spec.ts +1 -1
  19. package/__tests__/features/use-fetch/use-fetch.integration.spec.tsx +2 -2
  20. package/__tests__/features/use-fetch/use-fetch.keep-previous-data.spec.ts +1 -1
  21. package/__tests__/features/use-fetch/use-fetch.methods.spec.ts +1 -1
  22. package/__tests__/features/use-fetch/use-fetch.offline.spec.ts +1 -1
  23. package/__tests__/features/use-fetch/use-fetch.prefetch.spec.tsx +2 -2
  24. package/__tests__/features/use-fetch/use-fetch.refresh.spec.ts +3 -2
  25. package/__tests__/features/use-fetch/use-fetch.rerender.spec.tsx +3 -3
  26. package/__tests__/features/use-fetch/use-fetch.revalidate.spec.ts +47 -17
  27. package/__tests__/features/use-fetch/use-fetch.suspense.spec.tsx +4 -4
  28. package/__tests__/features/use-fetch/use-fetch.typescript.spec.ts +1 -2
  29. package/__tests__/features/use-fetch/use-fetch.utils.spec.ts +2 -2
  30. package/__tests__/features/use-fetch/use-fetch.window.spec.ts +1 -1
  31. package/__tests__/features/use-listener/use-listener.base.spec.ts +1 -1
  32. package/__tests__/features/use-queue/use-queue.actions.spec.ts +3 -3
  33. package/__tests__/features/use-queue/use-queue.base.spec.ts +13 -13
  34. package/__tests__/features/use-queue/use-queue.resolve.spec.ts +6 -6
  35. package/__tests__/features/use-stream/use-stream.base.spec.ts +1 -1
  36. package/__tests__/features/use-submit/use-submit.base.spec.ts +2 -2
  37. package/__tests__/features/use-submit/use-submit.cancel.spec.ts +1 -1
  38. package/__tests__/features/use-submit/use-submit.concurrency.spec.ts +1 -1
  39. package/__tests__/features/use-submit/use-submit.debounce.spec.ts +15 -15
  40. package/__tests__/features/use-submit/use-submit.methods.spec.ts +1 -1
  41. package/__tests__/features/use-submit/use-submit.optimistic.spec.ts +1 -1
  42. package/__tests__/features/use-submit/use-submit.queue.spec.ts +1 -1
  43. package/__tests__/features/use-submit/use-submit.retry.spec.ts +2 -2
  44. package/__tests__/features/use-submit/use-submit.revalidate.spec.ts +1 -1
  45. package/__tests__/features/use-submit/use-submit.submit.spec.ts +1 -1
  46. package/__tests__/features/use-submit/use-submit.typescript.spec.ts +2 -3
  47. package/__tests__/shared/isolation.tests.ts +1 -1
  48. package/__tests__/shared/response.tests.ts +2 -2
  49. package/__tests__/tsconfig.json +11 -17
  50. package/__tests__/utils/cache.utils.ts +6 -6
  51. package/__tests__/utils/use-app-manager.utils.ts +0 -1
  52. package/__tests__/utils/use-cache.utils.ts +0 -1
  53. package/__tests__/utils/use-emitter.utils.ts +1 -2
  54. package/__tests__/utils/use-fetch.utils.ts +0 -1
  55. package/__tests__/utils/use-listener.utils.ts +1 -2
  56. package/__tests__/utils/use-queue.utils.ts +4 -5
  57. package/__tests__/utils/use-request-events.utils.ts +0 -1
  58. package/__tests__/utils/use-socket-state.utils.ts +1 -2
  59. package/__tests__/utils/use-submit.utils.ts +0 -1
  60. package/__tests__/utils/use-tracked-state.utils.ts +0 -1
  61. package/dist/helpers/use-request-events/use-request-events.hooks.d.ts.map +1 -1
  62. package/dist/helpers/use-request-events/use-request-events.types.d.ts.map +1 -1
  63. package/dist/helpers/use-socket-state/use-socket-state.hooks.d.ts.map +1 -1
  64. package/dist/helpers/use-tracked-state/use-tracked-state.types.d.ts.map +1 -1
  65. package/dist/helpers/use-tracked-state/use-tracked-state.utils.d.ts.map +1 -1
  66. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts +1 -0
  67. package/dist/hooks/use-app-manager/use-app-manager.hooks.d.ts.map +1 -1
  68. package/dist/hooks/use-cache/use-cache.hooks.d.ts +1 -0
  69. package/dist/hooks/use-cache/use-cache.hooks.d.ts.map +1 -1
  70. package/dist/hooks/use-cache/use-cache.types.d.ts +2 -2
  71. package/dist/hooks/use-cache/use-cache.types.d.ts.map +1 -1
  72. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts +1 -0
  73. package/dist/hooks/use-emitter/use-emitter.hooks.d.ts.map +1 -1
  74. package/dist/hooks/use-emitter/use-emitter.types.d.ts +1 -0
  75. package/dist/hooks/use-emitter/use-emitter.types.d.ts.map +1 -1
  76. package/dist/hooks/use-fetch/use-fetch.constants.d.ts.map +1 -1
  77. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts +2 -1
  78. package/dist/hooks/use-fetch/use-fetch.hooks.d.ts.map +1 -1
  79. package/dist/hooks/use-fetch/use-fetch.types.d.ts.map +1 -1
  80. package/dist/hooks/use-listener/use-listener.hooks.d.ts +1 -0
  81. package/dist/hooks/use-listener/use-listener.hooks.d.ts.map +1 -1
  82. package/dist/hooks/use-listener/use-listener.types.d.ts +1 -0
  83. package/dist/hooks/use-listener/use-listener.types.d.ts.map +1 -1
  84. package/dist/hooks/use-queue/use-queue.constants.d.ts.map +1 -1
  85. package/dist/hooks/use-queue/use-queue.hooks.d.ts +2 -1
  86. package/dist/hooks/use-queue/use-queue.hooks.d.ts.map +1 -1
  87. package/dist/hooks/use-queue/use-queue.types.d.ts +6 -0
  88. package/dist/hooks/use-queue/use-queue.types.d.ts.map +1 -1
  89. package/dist/hooks/use-submit/use-submit.hooks.d.ts +2 -1
  90. package/dist/hooks/use-submit/use-submit.hooks.d.ts.map +1 -1
  91. package/dist/hooks/use-submit/use-submit.types.d.ts +1 -1
  92. package/dist/hooks/use-submit/use-submit.types.d.ts.map +1 -1
  93. package/dist/index.mjs +30 -22
  94. package/dist/index.mjs.map +1 -1
  95. package/dist/provider/provider.types.d.ts +4 -4
  96. package/dist/provider/provider.types.d.ts.map +1 -1
  97. package/dist/utils/bounce.utils.d.ts.map +1 -1
  98. package/dist/utils/deep-equal.utils.d.ts +2 -2
  99. package/dist/utils/deep-equal.utils.d.ts.map +1 -1
  100. package/dist/utils/tracked-proxy.utils.d.ts +1 -1
  101. package/dist/utils/tracked-proxy.utils.d.ts.map +1 -1
  102. package/package.json +8 -13
  103. package/src/helpers/use-request-events/use-request-events.hooks.ts +4 -5
  104. package/src/helpers/use-request-events/use-request-events.types.ts +0 -1
  105. package/src/helpers/use-socket-state/use-socket-state.hooks.ts +5 -6
  106. package/src/helpers/use-tracked-state/use-tracked-state.hooks.ts +11 -11
  107. package/src/helpers/use-tracked-state/use-tracked-state.types.ts +0 -1
  108. package/src/helpers/use-tracked-state/use-tracked-state.utils.ts +12 -13
  109. package/src/hooks/use-app-manager/use-app-manager.hooks.ts +2 -2
  110. package/src/hooks/use-cache/use-cache.hooks.ts +4 -4
  111. package/src/hooks/use-cache/use-cache.types.ts +2 -3
  112. package/src/hooks/use-emitter/use-emitter.hooks.ts +4 -4
  113. package/src/hooks/use-emitter/use-emitter.types.ts +1 -0
  114. package/src/hooks/use-fetch/use-fetch.constants.ts +0 -1
  115. package/src/hooks/use-fetch/use-fetch.hooks.ts +14 -10
  116. package/src/hooks/use-fetch/use-fetch.types.ts +0 -1
  117. package/src/hooks/use-listener/use-listener.hooks.ts +3 -3
  118. package/src/hooks/use-listener/use-listener.types.ts +1 -0
  119. package/src/hooks/use-queue/use-queue.constants.ts +0 -1
  120. package/src/hooks/use-queue/use-queue.hooks.ts +3 -3
  121. package/src/hooks/use-queue/use-queue.types.ts +6 -0
  122. package/src/hooks/use-stream/use-stream.hooks.ts +4 -4
  123. package/src/hooks/use-submit/use-submit.hooks.ts +7 -7
  124. package/src/hooks/use-submit/use-submit.types.ts +1 -2
  125. package/src/provider/provider.types.ts +4 -5
  126. package/src/utils/bounce.utils.ts +1 -0
  127. package/src/utils/deep-equal.utils.ts +28 -12
  128. package/src/utils/tracked-proxy.utils.ts +1 -1
  129. package/tsconfig.json +11 -2
  130. package/vite.config.ts +14 -20
  131. package/.eslintrc.cjs +0 -12
package/README.md CHANGED
@@ -1,6 +1,10 @@
1
- # ⚛️ React Hyper Fetch
1
+ # ⚛️ Hyper Fetch React
2
2
 
3
- <p>
3
+ <p align="center">
4
+ <b>React hooks for HyperFetch. Automatic fetching, caching, and real-time updates with full type safety.</b>
5
+ </p>
6
+
7
+ <p align="center">
4
8
  <a href="https://bettertyped.com/">
5
9
  <img src="https://custom-icon-badges.demolab.com/static/v1?label=&message=BetterTyped&color=333&logo=BT" />
6
10
  </a>
@@ -13,60 +17,206 @@
13
17
  <a href="https://www.npmjs.com/package/@hyper-fetch/react">
14
18
  <img src="https://custom-icon-badges.demolab.com/npm/v/@hyper-fetch/react.svg?logo=npm&color=e76f51" />
15
19
  </a>
20
+ <a href="https://www.npmjs.com/package/@hyper-fetch/react">
21
+ <img src="https://custom-icon-badges.demolab.com/npm/dm/@hyper-fetch/react?logoColor=fff&logo=trending-up" />
22
+ </a>
16
23
  <a href="https://github.com/BetterTyped/hyper-fetch">
17
24
  <img src="https://custom-icon-badges.demolab.com/badge/typescript-%23007ACC.svg?logo=typescript&logoColor=white" />
18
25
  </a>
19
- <a href="https://www.npmjs.com/package/@hyper-fetch/react">
26
+ <a href="https://bundlephobia.com/package/@hyper-fetch/react">
20
27
  <img src="https://custom-icon-badges.demolab.com/bundlephobia/minzip/@hyper-fetch/react?color=64BC4B&logo=package" />
21
28
  </a>
22
29
  </p>
23
30
 
24
- ## About
25
-
26
- **`React Hyper Fetch`** is a set of hooks for Hyper Fetch. Combined with React's lifecycle it allow to `create modern`,
27
- `optimized`, `maintainable` and `high quality solutions`. We offer many hooks for your use, thanks to which you can
28
- fetch or mutate data, observe sent requests and interact with data in the cache.
29
-
30
- ## Key Features
31
-
32
- 🔮 **Simple setup** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/basic/setup)
33
-
34
- 🎯 **Request cancellation** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/cancellation)
35
-
36
- ✨ **Window Focus/Blur Events** -
37
- [Read more](https://hyperfetch.bettertyped.com/docs/guides/react/core/window-focus-blur)
38
-
39
- 🚀 **Queueing** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/queueing)
40
-
41
- 💎 **Automatic caching** - [Read more](https://hyperfetch.bettertyped.com/docs/core/cache)
42
-
43
- 🪄 **Persistence** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/persistence)
44
-
45
- 🎊 **SSR Support** - [Read more](https://hyperfetch.bettertyped.com/docs/getting-started/environment)
46
-
47
- 🔋 **Offline First** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/offline)
48
-
49
- 📡 **Built-in adapter** - [Read more](https://hyperfetch.bettertyped.com/docs/core/adapter)
50
-
51
- 🧪 **Easy to test** - [Read more](https://hyperfetch.bettertyped.com/docs/getting-started/testing)
52
-
53
- 🎟 **Authentication** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/basic/authentication)
54
-
55
- 💡 **Prefetching** - [Read more](https://hyperfetch.bettertyped.com/docs/guides/advanced/prefetching)
56
-
57
- ## Help me keep working on this project ❤️
58
-
59
- - [Become a Sponsor on GitHub](https://github.com/sponsors/prc5)
60
-
61
- ## Sources
62
-
63
- - #### [Installation](https://hyperfetch.bettertyped.com/docs/getting-started/installation)
64
- - #### [Docs](https://hyperfetch.bettertyped.com/docs/react/overview)
65
- - #### [API](https://hyperfetch.bettertyped.com/api/)
66
- - #### [NPM](https://www.npmjs.com/package/@hyper-fetch/react)
67
- - #### [Guides](https://hyperfetch.bettertyped.com/guides/basic/setup)
68
-
69
- ## Other Packages
70
-
71
- - - #### [Hyper Fetch](https://github.com/BetterTyped/hyper-fetch/tree/main/packages/core)
72
- - #### [Hyper Fetch Sockets](https://github.com/BetterTyped/hyper-fetch/tree/main/packages/sockets)
31
+ ## 📖 About
32
+
33
+ `@hyper-fetch/react` connects HyperFetch's typed request system to React's component lifecycle. `useFetch` triggers
34
+ requests on mount and re-fetches when dependencies change. `useSubmit` gives you a `submit` function for mutations
35
+ triggered by user actions. Both hooks return fully typed `data`, `error`, and loading states with built-in callbacks.
36
+
37
+ ## 🎯 Key Capabilities
38
+
39
+ - ⚡ **Data on mount, zero boilerplate** — `useFetch` fetches, caches, and types your data automatically
40
+ - 🎯 **Mutations that just work** — `useSubmit` handles loading, errors, and success states for form submissions
41
+ - 🔄 **Always fresh data** — Auto-refetch on window focus, polling, and stale-time revalidation built in
42
+ - ✨ **Optimistic updates with rollback** — Update the UI instantly and auto-revert if the request fails
43
+ - 🔮 **Full type safety** — Every hook, callback, response, and error is typed end-to-end with zero `any`
44
+ - 🚀 **Instant page loads** — Prefetch data before components mount so users never wait
45
+ - 🔗 **No more useEffect spaghetti** — Dependent requests via `disabled` option, no manual orchestration
46
+ - 📡 **SSR out of the box** — Works with Next.js, Remix, and any server-rendered framework
47
+ - 💎 **Skip the state library** — No Redux or Zustand needed for server state — it's all handled
48
+
49
+ ## 🚀 Quick Start
50
+
51
+ ```bash
52
+ npm install @hyper-fetch/core @hyper-fetch/react
53
+ ```
54
+
55
+ ```tsx
56
+ import { useFetch } from "@hyper-fetch/react";
57
+ import { getUsers } from "./api";
58
+
59
+ const UserList = () => {
60
+ // Fetches on mount, returns typed data — no useEffect needed
61
+ const { data, loading, error } = useFetch(getUsers);
62
+
63
+ if (loading) return <p>Loading...</p>;
64
+ if (error) return <p>Something went wrong</p>;
65
+ return (
66
+ <ul>
67
+ {data?.map((user) => (
68
+ <li key={user.id}>{user.name}</li>
69
+ ))}
70
+ </ul>
71
+ );
72
+ };
73
+ ```
74
+
75
+ ## 📚 Documentation
76
+
77
+ - [Getting Started](https://hyperfetch.bettertyped.com/docs/getting-started/quick-start)
78
+ - [React Overview](https://hyperfetch.bettertyped.com/docs/react/overview)
79
+ - [API Reference](https://hyperfetch.bettertyped.com/api/)
80
+
81
+ ## 💡 Examples
82
+
83
+ ### Fetch with callbacks
84
+
85
+ ```tsx
86
+ import { useFetch } from "@hyper-fetch/react";
87
+
88
+ const UserProfile = ({ userId }: { userId: number }) => {
89
+ // setParams makes the request dynamic — re-fetches when userId changes
90
+ const { data, loading, error, onSuccess, onError } = useFetch(getUser.setParams({ userId }));
91
+
92
+ // Typed callbacks — response shape matches your request definition
93
+ onSuccess(({ response }) => {
94
+ console.log("Loaded user:", response.data.name);
95
+ });
96
+
97
+ onError(({ response }) => {
98
+ console.error("Failed to load user:", response.error);
99
+ });
100
+
101
+ if (loading) return <p>Loading...</p>;
102
+ if (error) return <p>Error: {error.message}</p>;
103
+ return <h1>{data.name}</h1>;
104
+ };
105
+ ```
106
+
107
+ ### Mutations with useSubmit
108
+
109
+ ```tsx
110
+ import { useSubmit } from "@hyper-fetch/react";
111
+
112
+ const CreateUserForm = () => {
113
+ // useSubmit doesn't fire on mount — it waits for you to call submit()
114
+ const { submit, submitting, onSubmitSuccess, onSubmitError } = useSubmit(createUser);
115
+
116
+ // Callbacks fire after each submission with typed response data
117
+ onSubmitSuccess(({ response }) => {
118
+ alert(`User ${response.data.name} created!`);
119
+ });
120
+
121
+ onSubmitError(({ response }) => {
122
+ alert(`Error: ${response.error.message}`);
123
+ });
124
+
125
+ const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
126
+ e.preventDefault();
127
+ const form = new FormData(e.currentTarget);
128
+ // Pass typed payload — TypeScript ensures the shape matches your request definition
129
+ submit({
130
+ data: { name: form.get("name") as string, email: form.get("email") as string },
131
+ });
132
+ };
133
+
134
+ return (
135
+ <form onSubmit={handleSubmit}>
136
+ <input name="name" placeholder="Name" required />
137
+ <input name="email" placeholder="Email" required />
138
+ <button type="submit" disabled={submitting}>
139
+ {submitting ? "Creating..." : "Create User"}
140
+ </button>
141
+ </form>
142
+ );
143
+ };
144
+ ```
145
+
146
+ ### Dependent requests
147
+
148
+ ```tsx
149
+ const UserPosts = ({ userId }: { userId: number }) => {
150
+ // First request fetches the user
151
+ const { data: user } = useFetch(getUser.setParams({ userId }));
152
+ // Second request waits until user is loaded — no useEffect chains needed
153
+ const { data: posts } = useFetch(getUserPosts.setParams({ userId }), {
154
+ disabled: !user,
155
+ });
156
+
157
+ return (
158
+ <div>
159
+ <h1>{user?.name}</h1>
160
+ {posts?.map((post) => (
161
+ <article key={post.id}>{post.title}</article>
162
+ ))}
163
+ </div>
164
+ );
165
+ };
166
+ ```
167
+
168
+ ### Optimistic updates with automatic rollback
169
+
170
+ ```tsx
171
+ import { useSubmit } from "@hyper-fetch/react";
172
+
173
+ const AddComment = ({ postId }: { postId: number }) => {
174
+ // setOptimistic runs BEFORE the request — update the list instantly
175
+ const optimisticAdd = addComment.setParams({ postId }).setOptimistic((request, client) => {
176
+ const cacheKey = getComments.setParams({ postId });
177
+ const previous = client.cache.get(cacheKey);
178
+
179
+ // Immediately insert the new comment into the cached list
180
+ const optimisticComment = { id: `temp-${Date.now()}`, text: request.data.text, author: "You" };
181
+ client.cache.set(cacheKey, {
182
+ ...previous,
183
+ data: [...(previous?.data || []), optimisticComment],
184
+ });
185
+
186
+ return {
187
+ context: { previous },
188
+ // If the request fails, put the old list back
189
+ rollback: () => client.cache.set(cacheKey, previous),
190
+ // On success, refetch to get the real server data
191
+ invalidate: [cacheKey],
192
+ };
193
+ });
194
+
195
+ const { submit, submitting, onSubmitError } = useSubmit(optimisticAdd);
196
+
197
+ // mutationContext is fully typed from your setOptimistic return
198
+ onSubmitError(({ mutationContext }) => {
199
+ console.log("Rolled back — restored", mutationContext?.previous?.data?.length, "comments");
200
+ });
201
+
202
+ const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
203
+ e.preventDefault();
204
+ const text = new FormData(e.currentTarget).get("text") as string;
205
+ submit({ data: { text } });
206
+ e.currentTarget.reset();
207
+ };
208
+
209
+ return (
210
+ <form onSubmit={handleSubmit}>
211
+ <input name="text" placeholder="Write a comment..." required />
212
+ <button type="submit" disabled={submitting}>
213
+ Post
214
+ </button>
215
+ </form>
216
+ );
217
+ };
218
+ ```
219
+
220
+ ## License
221
+
222
+ [MIT](https://github.com/BetterTyped/hyper-fetch/blob/main/License.md)
@@ -1,6 +1,6 @@
1
- import { act } from "@testing-library/react";
2
1
  import { createClient } from "@hyper-fetch/core";
3
2
  import { createHttpMockingServer } from "@hyper-fetch/testing";
3
+ import { act } from "@testing-library/react";
4
4
 
5
5
  import { renderUseRequestEvents } from "../../../utils";
6
6
 
@@ -1,5 +1,5 @@
1
- import { act } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { act } from "@testing-library/react";
3
3
 
4
4
  import { createRequest, renderUseRequestEvents } from "../../../utils";
5
5
 
@@ -1,6 +1,6 @@
1
- import { act } from "@testing-library/react";
2
1
  import { Socket } from "@hyper-fetch/sockets";
3
2
  import { createWebsocketMockingServer } from "@hyper-fetch/testing";
3
+ import { act } from "@testing-library/react";
4
4
 
5
5
  import { renderUseSocketState } from "../../../utils/use-socket-state.utils";
6
6
 
@@ -191,13 +191,13 @@ describe("useSocketState [ Base ]", () => {
191
191
  actions.setExtra({ test: true } as any);
192
192
  actions.setConnected(true);
193
193
  actions.setConnecting(true);
194
- actions.setTimestamp(12345);
194
+ actions.setTimestamp(12_345);
195
195
  });
196
196
 
197
197
  expect(view.result.current[0].data).toBe("some-data");
198
198
  expect(view.result.current[0].connected).toBe(true);
199
199
  expect(view.result.current[0].connecting).toBe(true);
200
- expect(view.result.current[0].timestamp).toBe(12345);
200
+ expect(view.result.current[0].timestamp).toBe(12_345);
201
201
 
202
202
  act(() => {
203
203
  view.result.current[1].clearState();
@@ -1,6 +1,6 @@
1
1
  import { createClient } from "@hyper-fetch/core";
2
- import { act, waitFor } from "@testing-library/react";
3
2
  import { createHttpMockingServer } from "@hyper-fetch/testing";
3
+ import { act, waitFor } from "@testing-library/react";
4
4
 
5
5
  import { renderUseTrackedState } from "../../../utils";
6
6
 
@@ -1,8 +1,8 @@
1
1
  import { createClient, xhrExtra } from "@hyper-fetch/core";
2
- import { act, waitFor } from "@testing-library/react";
3
2
  import { createHttpMockingServer, sleep } from "@hyper-fetch/testing";
4
-
3
+ import { act, waitFor } from "@testing-library/react";
5
4
  import { initialState } from "helpers";
5
+
6
6
  import { renderUseTrackedState } from "../../../utils";
7
7
 
8
8
  const { resetMocks, startServer, stopServer, mockRequest } = createHttpMockingServer();
@@ -68,10 +68,10 @@ describe("useTrackingState [ Events ]", () => {
68
68
  success: true,
69
69
  extra: xhrExtra,
70
70
  retries: 0,
71
- requestTimestamp: +new Date(),
72
- responseTimestamp: +new Date(),
73
- addedTimestamp: +new Date(),
74
- triggerTimestamp: +new Date(),
71
+ requestTimestamp: Date.now(),
72
+ responseTimestamp: Date.now(),
73
+ addedTimestamp: Date.now(),
74
+ triggerTimestamp: Date.now(),
75
75
  cacheKey: request.cacheKey,
76
76
  scope: request.scope,
77
77
  isCanceled: false,
@@ -95,10 +95,10 @@ describe("useTrackingState [ Events ]", () => {
95
95
  success: true,
96
96
  extra: xhrExtra,
97
97
  retries: 0,
98
- requestTimestamp: +new Date(),
99
- responseTimestamp: +new Date(),
100
- addedTimestamp: +new Date(),
101
- triggerTimestamp: +new Date(),
98
+ requestTimestamp: Date.now(),
99
+ responseTimestamp: Date.now(),
100
+ addedTimestamp: Date.now(),
101
+ triggerTimestamp: Date.now(),
102
102
  cacheKey: request.cacheKey,
103
103
  scope: request.scope,
104
104
  isCanceled: false,
@@ -131,10 +131,10 @@ describe("useTrackingState [ Events ]", () => {
131
131
  success: true,
132
132
  extra: xhrExtra,
133
133
  retries: 0,
134
- requestTimestamp: +new Date(),
135
- responseTimestamp: +new Date(),
136
- addedTimestamp: +new Date(),
137
- triggerTimestamp: +new Date(),
134
+ requestTimestamp: Date.now(),
135
+ responseTimestamp: Date.now(),
136
+ addedTimestamp: Date.now(),
137
+ triggerTimestamp: Date.now(),
138
138
  cacheKey: request.cacheKey,
139
139
  scope: request.scope,
140
140
  isCanceled: false,
@@ -168,10 +168,10 @@ describe("useTrackingState [ Events ]", () => {
168
168
  success: true,
169
169
  extra: xhrExtra,
170
170
  retries: 0,
171
- requestTimestamp: +new Date(),
172
- responseTimestamp: +new Date(),
173
- addedTimestamp: +new Date(),
174
- triggerTimestamp: +new Date(),
171
+ requestTimestamp: Date.now(),
172
+ responseTimestamp: Date.now(),
173
+ addedTimestamp: Date.now(),
174
+ triggerTimestamp: Date.now(),
175
175
  cacheKey: request.cacheKey,
176
176
  scope: request.scope,
177
177
  isCanceled: false,
@@ -204,10 +204,10 @@ describe("useTrackingState [ Events ]", () => {
204
204
  success: true,
205
205
  extra: xhrExtra,
206
206
  retries: 0,
207
- requestTimestamp: +new Date(),
208
- responseTimestamp: +new Date(),
209
- addedTimestamp: +new Date(),
210
- triggerTimestamp: +new Date(),
207
+ requestTimestamp: Date.now(),
208
+ responseTimestamp: Date.now(),
209
+ addedTimestamp: Date.now(),
210
+ triggerTimestamp: Date.now(),
211
211
  cacheKey: request.cacheKey,
212
212
  scope: request.scope,
213
213
  isCanceled: false,
@@ -243,10 +243,10 @@ describe("useTrackingState [ Events ]", () => {
243
243
  success: true,
244
244
  extra: xhrExtra,
245
245
  retries: 0,
246
- requestTimestamp: +new Date(),
247
- responseTimestamp: +new Date(),
248
- addedTimestamp: +new Date(),
249
- triggerTimestamp: +new Date(),
246
+ requestTimestamp: Date.now(),
247
+ responseTimestamp: Date.now(),
248
+ addedTimestamp: Date.now(),
249
+ triggerTimestamp: Date.now(),
250
250
  cacheKey: request.cacheKey,
251
251
  scope: request.scope,
252
252
  isCanceled: false,
@@ -287,7 +287,7 @@ describe("useTrackingState [ Events ]", () => {
287
287
  it("should map the async data", async () => {
288
288
  const { result } = renderUseTrackedState(
289
289
  request.setResponseMapper(async (response) => {
290
- return Promise.resolve({ ...response, data: "new-data" } as typeof response);
290
+ return { ...response, data: "new-data" } as typeof response;
291
291
  }),
292
292
  );
293
293
 
@@ -300,10 +300,10 @@ describe("useTrackingState [ Events ]", () => {
300
300
  success: true,
301
301
  extra: xhrExtra,
302
302
  retries: 0,
303
- requestTimestamp: +new Date(),
304
- responseTimestamp: +new Date(),
305
- addedTimestamp: +new Date(),
306
- triggerTimestamp: +new Date(),
303
+ requestTimestamp: Date.now(),
304
+ responseTimestamp: Date.now(),
305
+ addedTimestamp: Date.now(),
306
+ triggerTimestamp: Date.now(),
307
307
  cacheKey: request.cacheKey,
308
308
  scope: request.scope,
309
309
  isCanceled: false,
@@ -338,10 +338,10 @@ describe("useTrackingState [ Events ]", () => {
338
338
  success: true,
339
339
  extra: xhrExtra,
340
340
  retries: 0,
341
- requestTimestamp: +new Date(),
342
- responseTimestamp: +new Date(),
343
- addedTimestamp: +new Date(),
344
- triggerTimestamp: +new Date(),
341
+ requestTimestamp: Date.now(),
342
+ responseTimestamp: Date.now(),
343
+ addedTimestamp: Date.now(),
344
+ triggerTimestamp: Date.now(),
345
345
  cacheKey: request.cacheKey,
346
346
  scope: request.scope,
347
347
  isCanceled: false,
@@ -375,10 +375,10 @@ describe("useTrackingState [ Events ]", () => {
375
375
  success: true,
376
376
  extra: xhrExtra,
377
377
  retries: 0,
378
- requestTimestamp: +new Date(),
379
- responseTimestamp: +new Date(),
380
- addedTimestamp: +new Date(),
381
- triggerTimestamp: +new Date(),
378
+ requestTimestamp: Date.now(),
379
+ responseTimestamp: Date.now(),
380
+ addedTimestamp: Date.now(),
381
+ triggerTimestamp: Date.now(),
382
382
  cacheKey: request.cacheKey,
383
383
  scope: request.scope,
384
384
  isCanceled: false,
@@ -434,10 +434,10 @@ describe("useTrackingState [ Events ]", () => {
434
434
  success: true,
435
435
  extra: xhrExtra,
436
436
  retries: 0,
437
- requestTimestamp: +new Date(),
438
- responseTimestamp: +new Date(),
439
- addedTimestamp: +new Date(),
440
- triggerTimestamp: +new Date(),
437
+ requestTimestamp: Date.now(),
438
+ responseTimestamp: Date.now(),
439
+ addedTimestamp: Date.now(),
440
+ triggerTimestamp: Date.now(),
441
441
  cacheKey: request.cacheKey,
442
442
  scope: request.scope,
443
443
  isCanceled: false,
@@ -459,10 +459,10 @@ describe("useTrackingState [ Events ]", () => {
459
459
  success: true,
460
460
  extra: xhrExtra,
461
461
  retries: 0,
462
- requestTimestamp: +new Date(),
463
- responseTimestamp: +new Date(),
464
- addedTimestamp: +new Date(),
465
- triggerTimestamp: +new Date(),
462
+ requestTimestamp: Date.now(),
463
+ responseTimestamp: Date.now(),
464
+ addedTimestamp: Date.now(),
465
+ triggerTimestamp: Date.now(),
466
466
  cacheKey: request.cacheKey,
467
467
  scope: request.scope,
468
468
  isCanceled: false,
@@ -510,10 +510,10 @@ describe("useTrackingState [ Events ]", () => {
510
510
  success: true,
511
511
  extra: xhrExtra,
512
512
  retries: 0,
513
- requestTimestamp: +new Date(),
514
- responseTimestamp: +new Date(),
515
- addedTimestamp: +new Date(),
516
- triggerTimestamp: +new Date(),
513
+ requestTimestamp: Date.now(),
514
+ responseTimestamp: Date.now(),
515
+ addedTimestamp: Date.now(),
516
+ triggerTimestamp: Date.now(),
517
517
  cacheKey: request.cacheKey,
518
518
  scope: request.scope,
519
519
  isCanceled: false,
@@ -543,10 +543,10 @@ describe("useTrackingState [ Events ]", () => {
543
543
  success: true,
544
544
  extra: xhrExtra,
545
545
  retries: 0,
546
- requestTimestamp: +new Date(),
547
- responseTimestamp: +new Date(),
548
- addedTimestamp: +new Date(),
549
- triggerTimestamp: +new Date(),
546
+ requestTimestamp: Date.now(),
547
+ responseTimestamp: Date.now(),
548
+ addedTimestamp: Date.now(),
549
+ triggerTimestamp: Date.now(),
550
550
  cacheKey: request.cacheKey,
551
551
  scope: request.scope,
552
552
  isCanceled: false,
@@ -1,5 +1,4 @@
1
1
  import { createClient } from "@hyper-fetch/core";
2
-
3
2
  import { getValidCacheData, getInitialState, initialState } from "helpers";
4
3
  import { isEmpty, isEqual } from "utils";
5
4
 
@@ -16,7 +15,7 @@ describe("useTrackedState [ Utils ]", () => {
16
15
  expect(isEmpty(NaN)).toBe(false);
17
16
  expect(isEmpty("")).toBe(false);
18
17
  expect(isEmpty(false)).toBe(false);
19
- expect(isEmpty(undefined)).toBe(false);
18
+ expect(isEmpty()).toBe(false);
20
19
  expect(isEmpty(0)).toBe(false);
21
20
  expect(isEmpty(true)).toBe(false);
22
21
  expect(isEmpty(123)).toBe(false);
@@ -70,7 +69,7 @@ describe("useTrackedState [ Utils ]", () => {
70
69
 
71
70
  expect(isEqual(true, true)).toBe(true);
72
71
  expect(isEqual(false, false)).toBe(true);
73
- expect(isEqual(undefined, undefined)).toBe(true);
72
+ expect(isEqual()).toBe(true);
74
73
  expect(isEqual(null, null)).toBe(true);
75
74
  expect(isEqual(date, date)).toBe(true);
76
75
  expect(isEqual(date, date)).toBe(true);
@@ -135,8 +134,8 @@ describe("useTrackedState [ Utils ]", () => {
135
134
  data: "test-data",
136
135
  status: 200,
137
136
  success: true,
138
- requestTimestamp: new Date().getTime(),
139
- responseTimestamp: new Date().getTime(),
137
+ requestTimestamp: Date.now(),
138
+ responseTimestamp: Date.now(),
140
139
  };
141
140
 
142
141
  const result = getValidCacheData(mockRequest, initialResponse, null);
@@ -162,7 +161,7 @@ describe("useTrackedState [ Utils ]", () => {
162
161
  });
163
162
 
164
163
  it("should return cache data when not stale", () => {
165
- const currentTime = new Date().getTime();
164
+ const currentTime = Date.now();
166
165
  const cacheData = {
167
166
  data: "cached-data",
168
167
  error: null,
@@ -177,7 +176,7 @@ describe("useTrackedState [ Utils ]", () => {
177
176
  });
178
177
 
179
178
  it("should return stale cache data for stale-while-revalidate", () => {
180
- const staleTimestamp = new Date().getTime() - 5000; // Well beyond the 1000ms staleTime
179
+ const staleTimestamp = Date.now() - 5000; // Well beyond the 1000ms staleTime
181
180
  const cacheData = {
182
181
  data: "stale-data",
183
182
  error: null,
@@ -223,7 +222,7 @@ describe("useTrackedState [ Utils ]", () => {
223
222
 
224
223
  describe("when getInitialState handles sync responseMapper", () => {
225
224
  it("should apply sync responseMapper to cache data", () => {
226
- const currentTime = new Date().getTime();
225
+ const currentTime = Date.now();
227
226
  const cacheData = {
228
227
  data: "original-data",
229
228
  error: null,
@@ -242,7 +241,7 @@ describe("useTrackedState [ Utils ]", () => {
242
241
  });
243
242
 
244
243
  // eslint-disable-next-line @typescript-eslint/ban-ts-comment
245
- // @ts-ignore
244
+ // @ts-expect-error
246
245
  client.cache = {
247
246
  get: vi.fn().mockReturnValue(cacheData),
248
247
  version: "1",
@@ -1,15 +1,14 @@
1
- /* eslint-disable react/jsx-fragments */
2
- /* eslint-disable react/jsx-no-useless-fragment */
3
- import { Fragment } from "react";
4
1
  import type { HttpAdapterExtraType } from "@hyper-fetch/core";
5
2
  import { Client } from "@hyper-fetch/core";
6
3
  import { render, waitFor } from "@testing-library/react";
7
-
8
4
  import type { UseFetchReturnType } from "hooks/use-fetch";
9
5
  import { useFetch } from "hooks/use-fetch";
10
6
  import type { UseSubmitReturnType } from "hooks/use-submit";
11
7
  import { useSubmit } from "hooks/use-submit";
12
8
  import { Provider } from "provider";
9
+ /* eslint-disable react/jsx-fragments */
10
+ /* eslint-disable react/jsx-no-useless-fragment */
11
+ import { Fragment } from "react";
13
12
 
14
13
  describe("Provider [ Hydration ]", () => {
15
14
  const data = [1, 2, 3, 4, 5];
@@ -1,5 +1,4 @@
1
1
  import { act, render, screen, waitFor } from "@testing-library/react";
2
-
3
2
  import type { ProviderValueType } from "provider";
4
3
  import { Provider, useProvider } from "provider";
5
4
 
@@ -32,7 +31,7 @@ describe("useProvider [ Base ]", () => {
32
31
  });
33
32
  });
34
33
  it("should allow to modify received values", async () => {
35
- const customConfig = { useFetchConfig: { bounceTime: 99999 } };
34
+ const customConfig = { useFetchConfig: { bounceTime: 99_999 } };
36
35
  render(<App />);
37
36
 
38
37
  act(() => {
@@ -1,5 +1,5 @@
1
- import { act } from "@testing-library/react";
2
1
  import { createHttpMockingServer } from "@hyper-fetch/testing";
2
+ import { act } from "@testing-library/react";
3
3
 
4
4
  import { client, renderUseAppManager } from "../../utils";
5
5