Skip to content

v7.0.0 #103

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 426 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
426 commits
Select commit Hold shift + click to select a range
2c44009
docs: Docs adjustments
prc5 Dec 19, 2024
8c6780a
feat: changes
prc5 Dec 29, 2024
2c527bb
tests: update
prc5 Dec 29, 2024
b2c5f0b
tests: update
prc5 Dec 29, 2024
60940e8
fix - app.manager.ts focus initialization
GerasNyx Jan 5, 2025
cb71aa8
improvements to the logger
prc5 Jan 20, 2025
bca7f01
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 Jan 20, 2025
98969e9
improvements to the logger
prc5 Jan 20, 2025
c553023
improvements to the mocker
prc5 Jan 20, 2025
bd7fcb6
improvements to the mocker
prc5 Jan 20, 2025
78aac19
improvements to the tests
prc5 Jan 21, 2025
4c21c6e
improvements to the tests
prc5 Jan 21, 2025
88bf060
improvements to the tests
prc5 Jan 21, 2025
c8d2afd
improvements to the tests
prc5 Jan 22, 2025
d8aeaa5
improvements to the tests
prc5 Jan 22, 2025
05859a0
improvements to the tests
prc5 Jan 23, 2025
d5ba61c
improvements to the tests
prc5 Jan 27, 2025
b00d28b
improvements
prc5 Feb 5, 2025
c1f9223
Merged react and devtools standalone
GerasNyx Feb 6, 2025
101eaf0
new adapter
prc5 Feb 7, 2025
65ece9e
new adapter
prc5 Feb 7, 2025
725524c
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 Feb 7, 2025
da110ca
sockets import fixes
GerasNyx Feb 7, 2025
c7b5aa3
new adapter
prc5 Feb 7, 2025
0f99f36
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 Feb 7, 2025
b1d27b4
Fixes and adjustments
GerasNyx Feb 7, 2025
5d17bda
new adapter
prc5 Feb 8, 2025
8b00993
new adapter
prc5 Feb 8, 2025
e5adba0
new adapter
prc5 Feb 8, 2025
9a42c9b
new adapter
prc5 Feb 8, 2025
5b2a071
Added listener in plugin
GerasNyx Feb 8, 2025
ec2e6bf
new adapter
prc5 Feb 9, 2025
12bd920
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 Feb 9, 2025
17233a6
new adapter
prc5 Feb 9, 2025
5f8b6dd
new adapter
prc5 Feb 9, 2025
0d6a38e
new adapter
prc5 Feb 9, 2025
f1e2294
new adapter
prc5 Feb 9, 2025
6a34c42
new adapter
prc5 Feb 9, 2025
80b7203
new adapter
prc5 Feb 9, 2025
8a44a12
Test adapter fix
GerasNyx Feb 9, 2025
06b9c48
new adapter
prc5 Feb 9, 2025
caa3159
console.logs
GerasNyx Feb 10, 2025
9954193
tests: update
prc5 Feb 10, 2025
0831402
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 Feb 10, 2025
3dcf174
tests: update
prc5 Feb 10, 2025
e8fa075
tests: update
prc5 Feb 10, 2025
40cdfde
tests: update
prc5 Feb 11, 2025
190bcc5
tests: update
prc5 Feb 11, 2025
9d88b35
tests: update
prc5 Feb 11, 2025
ae08faa
sockets update
prc5 Feb 11, 2025
c99ba56
tests: update
prc5 Feb 11, 2025
7efcfbb
tests: 100%
prc5 Feb 13, 2025
97be295
tests: 100%
prc5 Feb 13, 2025
8399ee1
sockets
prc5 Feb 13, 2025
3221890
Adjusted setting cache from devtools
GerasNyx Feb 14, 2025
6b9ccd1
tests: 100%
prc5 Feb 14, 2025
f231c18
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 Feb 14, 2025
50f020d
tests: 100%
prc5 Feb 14, 2025
eff12cb
tests: 100%
prc5 Feb 14, 2025
0a469dd
tests: 100%
prc5 Feb 14, 2025
179291a
tests: 100%
prc5 Feb 14, 2025
69ed8a1
tests: 100%
prc5 Feb 15, 2025
616ffb1
tests: 100%
prc5 Feb 15, 2025
4449d79
sockets new adapter
prc5 Feb 17, 2025
c94e9e8
sockets new adapter
prc5 Feb 18, 2025
63429a4
sockets new adapter
prc5 Feb 18, 2025
eea6f2a
sockets new adapter
prc5 Feb 18, 2025
9df8c05
sockets new adapter
prc5 Feb 18, 2025
6db75c5
sockets new adapter
prc5 Feb 18, 2025
1888d02
sockets new adapter
prc5 Feb 18, 2025
26e8d7f
sockets new adapter
prc5 Feb 18, 2025
cf04430
tests: fixes
prc5 Feb 18, 2025
5794480
tests: fixes
prc5 Feb 18, 2025
4a2812a
tests: 100%
prc5 Feb 19, 2025
1edb469
tests: 100%
prc5 Feb 20, 2025
c2d3967
tests: 100%
prc5 Feb 20, 2025
fe19610
tests: 100%
prc5 Feb 20, 2025
dd403a2
tests: 100%
prc5 Feb 20, 2025
b8e1d6c
tests: 100%
prc5 Feb 20, 2025
38f2aca
tests: 100%
prc5 Feb 20, 2025
4641446
tests: 100%
prc5 Feb 20, 2025
609f9ea
tests: 100%
prc5 Feb 20, 2025
17329c7
- Devtools changes
GerasNyx Feb 21, 2025
9c3fc1c
Merge remote-tracking branch 'origin/6.0.0' into 6.0.0
GerasNyx Feb 21, 2025
1931f77
tests: 100%
prc5 Feb 21, 2025
6026438
Electron app
prc5 Feb 22, 2025
5563347
- Added devtools reconnection for frontend and for plugin
GerasNyx Feb 24, 2025
42f5bda
fix app env
prc5 Feb 25, 2025
329982c
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 Feb 25, 2025
6fd5761
fix app env
prc5 Feb 25, 2025
2071af8
fix app env
prc5 Feb 25, 2025
9a55dae
devtools wip
prc5 Mar 1, 2025
978c4ce
new design
prc5 Mar 2, 2025
d5e9eb2
yarn fix
prc5 Mar 3, 2025
3760ea8
yarn fix
prc5 Mar 3, 2025
c760ea6
devtools
prc5 Mar 3, 2025
5791e3e
devtools progress
prc5 Mar 19, 2025
189e510
Merge branch 'main' into 6.0.0
prc5 Mar 20, 2025
c45ec93
fixes to the building process
prc5 Mar 20, 2025
709f2f4
new devtools ui
prc5 Mar 21, 2025
9bc23e5
new devtools ui
prc5 Mar 28, 2025
b528b56
new devtools ui
prc5 Mar 29, 2025
114831b
new devtools ui
prc5 Mar 29, 2025
b1e1ff1
new devtools ui
prc5 Mar 30, 2025
e1f9d4d
new devtools ui
prc5 Mar 30, 2025
01d5080
new devtools ui
prc5 Mar 31, 2025
f6dece8
- Devtools <-> Client communication improvements + metaData passing
GerasNyx Mar 31, 2025
27bb515
new devtools ui
prc5 Apr 2, 2025
246ceb5
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 Apr 2, 2025
00592c3
new devtools ui
prc5 Apr 3, 2025
b0a2f71
new devtools ui
prc5 Apr 7, 2025
a234c19
devtools progress
prc5 Apr 13, 2025
f284988
devtools progress
prc5 Apr 13, 2025
2a95c58
devtools progress
prc5 Apr 13, 2025
6d89366
devtools progress
prc5 Apr 13, 2025
0412e04
Devtools socket server - handled frontend refresh
GerasNyx Apr 13, 2025
2469f29
Server refactor
GerasNyx Apr 14, 2025
80a9c44
devtools progress
prc5 Apr 14, 2025
4c839a4
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 Apr 14, 2025
cc871a6
devtools progress
prc5 Apr 14, 2025
47d46f3
devtools progress
prc5 Apr 14, 2025
3dc48fc
Handled plugin hangup case
GerasNyx Apr 14, 2025
a653877
devtools progress
prc5 Apr 14, 2025
50f3378
devtools progress
prc5 Apr 14, 2025
b9caddd
devtools progress
prc5 Apr 14, 2025
eb6bbac
devtools progress
prc5 Apr 14, 2025
82594b7
devtools progress
prc5 Apr 14, 2025
7da75ae
Fix for app name - removed prefix.
GerasNyx Apr 15, 2025
d4a9810
devtools progress
prc5 Apr 16, 2025
16463c5
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 Apr 16, 2025
07bd90e
devtools progress
prc5 Apr 16, 2025
4f81df6
devtools progress
prc5 Apr 16, 2025
1177e46
devtools progress
prc5 Apr 16, 2025
fbcd192
devtools progress
prc5 Apr 17, 2025
51cf5a1
added error handler
prc5 Apr 17, 2025
46f9168
devtools progress
prc5 Apr 20, 2025
6083fe6
devtools progress
prc5 Apr 20, 2025
beb145d
devtools progress
prc5 Apr 21, 2025
4d58a9b
devtools progress
prc5 Apr 21, 2025
6b658e8
devtools progress
prc5 Apr 21, 2025
1bc41b1
devtools progress
prc5 Apr 21, 2025
59ae48b
devtools progress
prc5 Apr 22, 2025
59f916a
progress
prc5 Apr 23, 2025
1a580ee
progress
prc5 Apr 23, 2025
29aa116
progress
prc5 Apr 24, 2025
9d61468
progress
prc5 Apr 24, 2025
96c2050
progress
prc5 Apr 24, 2025
ce81a59
progress
prc5 Apr 24, 2025
5279492
progress
prc5 Apr 24, 2025
7d04691
progress
prc5 Apr 25, 2025
26b34aa
progress
prc5 Apr 25, 2025
646488c
progress
prc5 Apr 25, 2025
e76265f
progress
prc5 Apr 25, 2025
ab02e60
progress
prc5 Apr 26, 2025
59d8aad
progress
prc5 Apr 26, 2025
a0b3ebb
progress
prc5 Apr 27, 2025
7e6d4ca
progress
prc5 Apr 28, 2025
53e0665
progress
prc5 Apr 28, 2025
2bf5600
progress
prc5 Apr 29, 2025
1b62980
progress
prc5 Apr 30, 2025
92e50b0
progress
prc5 Apr 30, 2025
4369462
progress
prc5 Apr 30, 2025
5fb7fc1
progress
prc5 May 1, 2025
f546c15
progress
prc5 May 1, 2025
66a8238
progress
prc5 May 1, 2025
c7e5c15
progress
prc5 May 1, 2025
ad84e64
progress
prc5 May 2, 2025
6bb8389
progress
prc5 May 2, 2025
628b2b0
progress
prc5 May 2, 2025
d9ef68f
progress
prc5 May 2, 2025
975577c
progress
prc5 May 2, 2025
7ee33e2
progress
prc5 May 2, 2025
0daf0c2
progress
prc5 May 2, 2025
96acde1
progress
prc5 May 2, 2025
b1c5ddb
progress
prc5 May 2, 2025
6297f39
progress
prc5 May 2, 2025
ccec022
docs linls
prc5 May 3, 2025
d0d0138
docs links
prc5 May 3, 2025
b056b99
docs
prc5 May 4, 2025
52ea4d7
docs
prc5 May 4, 2025
d1fb841
docs
prc5 May 4, 2025
492b09a
docs
prc5 May 5, 2025
94d73f3
docs
prc5 May 5, 2025
702fb70
docs
prc5 May 6, 2025
6547e4f
docs
prc5 May 6, 2025
12f1af7
progress
prc5 May 6, 2025
9cdb6c1
docs
prc5 May 6, 2025
defb2ba
docs
prc5 May 6, 2025
e854b3e
docs
prc5 May 6, 2025
9c9b52d
docs
prc5 May 6, 2025
dd220a0
progress
prc5 May 7, 2025
1d14513
progress
prc5 May 7, 2025
d0c58cc
progress
prc5 May 7, 2025
1b67a74
progress
prc5 May 7, 2025
22adf01
progress
prc5 May 7, 2025
85b643b
progress
prc5 May 7, 2025
f2b3fa5
progress
prc5 May 7, 2025
764edb6
Fix for ubuntu devtools popup
GerasNyx May 7, 2025
08b3d19
license
prc5 May 8, 2025
6b5ae1d
Merge branch '6.0.0' of github.com:BetterTyped/hyper-fetch into 6.0.0
prc5 May 8, 2025
93cc3bf
progress
prc5 May 9, 2025
862cca4
progress
prc5 May 10, 2025
833a117
progress
prc5 May 10, 2025
d2324cf
progress
prc5 May 10, 2025
53df42d
progress
prc5 May 11, 2025
c81fa8b
progress
prc5 May 12, 2025
3402de4
progress
prc5 May 12, 2025
d3197ee
progress
prc5 May 12, 2025
aae2657
progress
prc5 May 13, 2025
e1f14ad
progress
prc5 May 14, 2025
6566a6c
progress
prc5 May 15, 2025
7ac9cd6
progress
prc5 May 15, 2025
19c8ce1
progress
prc5 May 15, 2025
ec56c73
progress
prc5 May 15, 2025
9b60f80
progress
prc5 May 15, 2025
33ec1ae
progress
prc5 May 22, 2025
b5c40d6
progress
prc5 May 30, 2025
6bf6d3f
progress
prc5 May 30, 2025
5583d05
progress
prc5 May 30, 2025
708bc2a
progress
prc5 May 30, 2025
85a305e
progress
prc5 May 30, 2025
2f0336b
progress
prc5 May 30, 2025
e24cf4b
progress
prc5 May 30, 2025
e2d42e9
progress
prc5 May 31, 2025
1e1131f
progress
prc5 May 31, 2025
a9e3457
progress
prc5 Jun 2, 2025
5e7bbdf
progress
prc5 Jun 2, 2025
5ae91e8
progress
prc5 Jun 2, 2025
7c8b177
progress
prc5 Jun 2, 2025
db87e2c
progress
prc5 Jun 3, 2025
35e254d
progress
prc5 Jun 8, 2025
b7b1e0a
progress
prc5 Jun 9, 2025
d798cc3
progress
prc5 Jun 10, 2025
cca1a48
progress
prc5 Jun 10, 2025
a7de03d
progress
prc5 Jun 10, 2025
e296879
progress
prc5 Jun 10, 2025
da95412
progress
prc5 Jun 10, 2025
d450396
progress
prc5 Jun 11, 2025
4431223
progress
prc5 Jun 11, 2025
5aa7643
progress
prc5 Jun 11, 2025
0d4519b
progress
prc5 Jun 11, 2025
a7edebb
progress
prc5 Jun 11, 2025
85f525b
progress
prc5 Jun 11, 2025
69e113d
progress
prc5 Jun 11, 2025
5a691be
progress
prc5 Jun 13, 2025
8d4bfff
progress
prc5 Jun 13, 2025
29a9744
progress
prc5 Jun 13, 2025
e5651aa
progress
prc5 Jun 13, 2025
7b1dfd8
progress
prc5 Jun 14, 2025
3ae87b0
progress
prc5 Jun 17, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
14 changes: 14 additions & 0 deletions .babelrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
babelrcRoots: ["packages/*"],
plugins: ["babel-plugin-transform-vite-meta-env"],
presets: [
"@babel/preset-env",
"@babel/preset-typescript",
[
"@babel/preset-react",
{
runtime: "automatic",
},
],
],
};
7 changes: 7 additions & 0 deletions .cursor/mcp.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"mcpServers": {
"nx-mcp": {
"url": "http://localhost:9057/sse"
}
}
}
396 changes: 396 additions & 0 deletions .cursor/rules/documentation.mdc

Large diffs are not rendered by default.

324 changes: 324 additions & 0 deletions .cursor/rules/hyper-fetch-react.mdc
Original file line number Diff line number Diff line change
@@ -0,0 +1,324 @@
---
description:
globs: *.tsx
alwaysApply: false
---

# Hyper Fetch - Best Practices for React

This document outlines the best practices for using hyper-fetch in React applications, covering various aspects such as
code organization, performance considerations, security, and testing. Following these guidelines ensures consistency,
maintainability, and optimal usage of HyperFetch's features.

## 1. Code Organization and Structure

### Directory Structure Best Practices

- **Feature-based Organization:** Group hyper-fetch requests and related components within feature-specific directories.
This improves modularity and maintainability.

```
src/
├── features/
│ ├── users/
│ │ ├── components/
│ │ │ ├── user-list.tsx
│ │ │ └── user-details.tsx
│ │ ├── api/
│ │ │ └── users-api.ts
│ │ └── types/
│ │ └── user.ts
│ ├── products/
│ └── ...
├── ...

```

- **Dedicated API Service Layer:** Abstract API interaction logic into separate modules. This allows for easier testing
and decoupling of components from specific API implementations. Consider using a dedicated `api` directory within each
feature.

### File Naming Conventions

- **Consistent Naming:** Follow a consistent naming convention for hyper-fetch hooks. Prefix requests with method like
`get` | `create` | `update` | `delete` and postfix with `Request` to clearly indicate their purpose (e.g.,
`getUserRequest`, `createNoteRequest`).

- **Descriptive Names:** Use descriptive names for files and variables to improve code readability. For example,
`getUsersRequest.ts` is more informative than `usersRequest.ts`.

---

---

## 2. Common Patterns and Anti-patterns

### 2.1 Design Patterns Specific to hyper-fetch

- **Custom Hooks for Data Fetching:** As highlighted earlier, encapsulating hyper-fetch logic within custom hooks. This
promotes reusability and separation of concerns. These hooks will typically return the result of a `useQuery` or
`useMutation` call.

- **Optimistic Updates:** Implement optimistic updates to improve perceived performance. This involves updating the UI
before the API request completes, and then reverting the changes if the request fails. hyper-fetch provides utilities
like `onMutate` to handle this.

- **Pessimistic Updates:** Update the UI only after a successful response from the API. Simpler to implement but
provides a less snappy user experience.

### 2.2 Recommended Approaches for Common Tasks

- **Prefetching Data:** Prefetch data for routes or components that the user is likely to visit next. This can
significantly improve the user experience. Use `request.send()`.

- **Dependent Queries:** Fetch data based on the result of a previous query. Use the `enabled` option in `useQuery` to
conditionally execute queries.

```typescript
const { data: user } = useFetch(getUser);
const { data: posts } = useFetch(getPosts.setParams({ userId: user?.id }), { disabled: !user });
```

### 2.3 Anti-patterns and Code Smells to Avoid

- **Directly Calling API in Components:** Avoid making API calls directly within components. This makes testing
difficult and tightly couples components to specific API implementations.

- **Ignoring Error Handling:** Always handle errors properly. Display user-friendly error messages and provide options
for retrying requests.

- **Over-fetching Data:** Fetch only the data that is required by the component. Use GraphQL or API query parameters to
reduce the amount of data transferred.

- **Deeply Nested Queries:** Avoid deeply nesting queries, as this can lead to performance issues and make the code
difficult to understand. Consider combining queries or using a different approach.

### 2.4 State Management Best Practices

- **Local vs. Global State:** Determine whether data should be stored in local component state or in a global state
management solution. Use local state for component-specific data and global state for data that needs to be shared
across multiple components.

- **hyper-fetch as a State Manager:** Leverage hyper-fetch's built-in caching and state management capabilities. Avoid
using external state management libraries for data that is already managed by hyper-fetch.

### 2.5 Error Handling Patterns

- **Centralized Error Handling:** Implement centralized error handling to provide consistent error messages and logging.

- **Retry Logic:** Implement retry logic to automatically retry failed requests. hyper-fetch provides options for
configuring retry behavior.

- **Error Boundaries:** Use Error Boundaries to catch errors that occur during rendering. This prevents the entire
application from crashing.

## 3. Performance Considerations

### 3.1 Optimization Techniques - Hooks

- **Query Invalidation:** Invalidate queries when data changes. This ensures that the UI is always up-to-date.

- **Stale-While-Revalidate:** Use the `staleTime` and `cacheTime` options to configure how long data should be
considered fresh. `Stale While Revalidate` allows the UI to display cached data while fetching fresh data in the
background. This can be passed to the hook like: `useFetch(request, { revalidate: true })`

- **Window Focus Refetching:** Configure refetching on window focus to keep data fresh when the user switches back to
the application.

- **Polling/Refetch Intervals:** Use `refreshTime` to periodically refetch data. This is useful for data that changes
frequently.

### 3.2 Memory Management

- **Query Cache Management:** Understand how hyper-fetch manages its cache. Configure the `staleTime` option to control
how long data is stored in the cache.

- **Garbage Collection:** Ensure that unused queries are garbage collected properly. Use the `cacheTime` option to
configure how long inactive queries should be kept in the cache.

### 3.3 Rendering Optimization

- **Memoization:** Use `React.memo` to prevent unnecessary re-renders of components. This is especially important for
components that display data fetched from hyper-fetch.

- **Virtualization:** Use virtualization techniques (e.g., `react-window`, `react-virtualized`) to efficiently render
large lists of data.

### 3.4 Bundle Size Optimization

- **Tree Shaking:** Ensure that your build process is configured for tree shaking. This removes unused code from the
final bundle.

- **Code Splitting:** As mentioned earlier, use code splitting to reduce the initial load time.

### 3.5 Lazy Loading Strategies

- **Lazy Load Components:** Use `React.lazy` to lazy load components that are not immediately needed.

- **Lazy Load Data:** Fetch data only when it is needed. Use dependent queries to fetch data based on user interactions.

## 4. Security Best Practices

### Common Vulnerabilities and How to Prevent Them

- **Cross-Site Scripting (XSS):** Sanitize user input to prevent XSS attacks. Use a library like DOMPurify to sanitize
HTML.

- **Cross-Site Request Forgery (CSRF):** Implement CSRF protection to prevent attackers from performing actions on
behalf of the user. Use a library or framework that provides CSRF protection.

- **Injection Attacks:** Protect against injection attacks by validating user input and using parameterized queries.

### Input Validation

- **Client-Side Validation:** Implement client-side validation to provide immediate feedback to the user.

- **Server-Side Validation:** Always validate user input on the server-side to prevent malicious data from being stored
in the database.

### Authentication and Authorization Patterns

- **JSON Web Tokens (JWT):** Use JWTs for authentication. Store the JWT in a secure cookie or in local storage (with
caution). Use `httpOnly` flag on cookies containing JWTs when possible to prevent client-side script access.

- **Role-Based Access Control (RBAC):** Implement RBAC to control access to different parts of the application. Use
middleware or custom hooks to check user roles.

### Data Protection Strategies

- **Encryption:** Encrypt sensitive data at rest and in transit. Use HTTPS to encrypt data in transit. Encrypt sensitive
data in the database.

- **Data Masking:** Mask sensitive data in logs and reports. This prevents sensitive data from being exposed to
unauthorized users.

### Secure API Communication

- **HTTPS:** Use HTTPS for all API communication. This encrypts data in transit and prevents eavesdropping.

- **API Rate Limiting:** Implement API rate limiting to prevent abuse.

- **CORS:** Configure CORS properly to prevent cross-origin requests from unauthorized domains.

## 5. Testing Approaches

### Unit Testing Strategies

- **Test Custom Hooks:** Unit test custom hyper-fetch hooks to ensure they are working correctly. Mock the API calls
using libraries like `msw` (Mock Service Worker).

- **Test Components in Isolation:** Unit test components in isolation to ensure they render correctly and handle user
interactions properly. Use libraries like `react-testing-library`.

### Integration Testing

- **Test Data Flow:** Integration test the data flow between components and APIs. Verify that data is fetched correctly
and displayed properly.

- **Test Error Handling:** Integration test error handling scenarios to ensure that errors are handled properly.

### End-to-End Testing

- **Simulate User Interactions:** Use end-to-end testing frameworks like Cypress or Playwright to simulate user
interactions and verify that the application is working correctly from the user's perspective.

- **Test Critical Paths:** Focus on testing critical user flows, such as login, registration, and checkout.

### Test Organization

- **Colocate Tests with Components:** Colocate tests with the components they are testing. This makes it easier to find
and maintain tests.

- **Use Descriptive Test Names:** Use descriptive test names to clearly indicate what each test is verifying.

### Mocking and Stubbing

- **Build-in:** Use built in abilities of HyperFetch to mock requests.

```ts
const request = client.createRequest()({ endpoint: "shared-base-endpoint" });

// Set mock is the only method that modify reference
request.setMock(
() => {
// Data part
return {
data: { mocking: "is fun" },
status: 200,
};
},
{
// Config part
requestTime: 40,
responseTime: 60,
totalUploaded: 1000,
totalDownloaded: 1000,
},
);
```

- **Mock API Calls:** Use mocking libraries like `msw` to mock API calls during testing. This allows you to test
components in isolation without relying on a real API.

- **Stub External Dependencies:** Stub external dependencies to isolate components and make tests more predictable.

## 6. Common Pitfalls and Gotchas

- **Forgetting to Invalidate Queries:** Failing to invalidate queries when data changes can lead to stale data being
displayed in the UI.

- **Incorrect Cache Configuration:** Incorrectly configuring the `cacheTime` and `staleTime` options can lead to
performance issues or stale data.

- **Not Handling Errors Properly:** Not handling errors properly can lead to unexpected behavior and a poor user
experience.

- **Over-relying on Default Configuration:** Customizing hyper-fetch to match specific needs is essential.

- **Ignoring Devtools:** The hyper-fetch devtools are invaluable for debugging and understanding what is happening under
the hood.

## 7. Tooling and Environment

### 7.1 Recommended Development Tools

- **VS Code:** Use VS Code with extensions like ESLint, Prettier, and TypeScript to improve developer productivity.

- **React Developer Tools:** Use the React Developer Tools browser extension to inspect React components and state.

- **Hyper Fetch Devtools - HyperFlow:** Use the HyperFlow Devtools to inspect the hyper-fetch cache, network and track
query and mutation status.

### 7.2 Build Configuration

- **Webpack or Parcel:** Use a bundler like Webpack or Parcel to bundle your code for production. Configure the bundler
for tree shaking and code splitting.

- **Babel:** Use Babel to transpile your code to older versions of JavaScript. This ensures that your code is compatible
with older browsers.

### 7.3 Linting and Formatting

- **ESLint:** Use ESLint to enforce coding standards and prevent errors. Install dedicated linter package to avoid
common typescript issues. `@hyper-fetch/eslint`

- **Prettier:** Use Prettier to automatically format your code. This ensures that your code is consistently formatted
and easy to read.

### 7.4 Deployment Best Practices

- **CDN:** Use a CDN to serve static assets. This improves performance and reduces the load on your server.

- **Caching:** Configure caching properly on your server and CDN. This reduces the number of requests to your server and
improves performance.

### 7.5 CI/CD Integration

- **Automated Testing:** Integrate automated testing into your CI/CD pipeline. This ensures that your code is tested
automatically before it is deployed.

- **Automated Deployment:** Automate the deployment process to reduce the risk of errors and improve efficiency.

```

```
Loading
Loading