You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const todo =useCache(TodoResource.get, { id: 5 });
17
18
const todo =useQuery(Todo, { id: 5 });
18
19
```
19
20
21
+
For API definitions (like TodoResource), refer to the [@data-client/rest guide](.github/instructions/rest.instructions.md).
22
+
20
23
## Mutations
21
24
22
25
```ts
@@ -63,7 +66,8 @@ return (
63
66
64
67
## Components
65
68
66
-
Prefer using `AsyncBoundary` for error handling and loading states. Its props are `fallback`, `errorComponent`, and `errorClassName` and `listen`. It can be used to wrap any component that fetches data.
69
+
Prefer using [AsyncBoundary](https://dataclient.io/docs/api/AsyncBoundary) for error handling and loading states.
70
+
Its props are `fallback`, `errorComponent`, and `errorClassName` and `listen`. It can be used to wrap any component that fetches data.
67
71
68
72
```tsx
69
73
<AsyncBoundarylisten={history.listen}>
@@ -73,7 +77,8 @@ Prefer using `AsyncBoundary` for error handling and loading states. Its props ar
73
77
74
78
## Type-safe imperative actions
75
79
76
-
`Controller` is returned from `useController()`. It has: ctrl.fetch(), ctrl.fetchIfStale(), ctrl.expireAll(), ctrl.invalidate(), ctrl.invalidateAll(), ctrl.setResponse(), ctrl.set().
80
+
[Controller](https://dataclient.io/docs/api/Controller) is returned from `useController()`. It has:
Customer managers allow for global side effect handling. They interface with the store using `Controller`, and middleware is run in response to actions.
107
+
Customer [managers](https://dataclient.io/docs/api/Manager) allow for global side effect handling.
108
+
They interface with the store using `Controller`, and middleware is run in response to actions.
Copy file name to clipboardExpand all lines: .github/instructions/rest.instructions.md
+29-43Lines changed: 29 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,26 +3,26 @@ applyTo: '**/*.ts*'
3
3
---
4
4
# Guide: Using `@data-client/rest` for Resource Modeling
5
5
6
-
This project uses `@data-client/rest` to define, fetch, normalize, and update RESTful resources and entities in React/TypeScript apps with type safety and automatic cache management.
6
+
This project uses [@data-client/rest](https://dataclient.io/rest) to define, fetch, normalize, and update RESTful resources and entities in React/TypeScript apps with type safety and automatic cache management.
7
7
**Always follow these patterns when generating code that interacts with remote APIs.**
8
8
9
9
---
10
10
11
11
## 1. Defining Schemas
12
12
13
-
Define `schemas` to represent the JSON returned by an endpoint. Compose these
13
+
Define [schemas](https://dataclient.io/rest/api/schema) to represent the JSON returned by an endpoint. Compose these
14
14
to represent the data expected.
15
15
16
16
### Object
17
17
18
-
-`Entity` - represents a single unique object (denormalized)
19
-
-`schema.Union(Entity)` - polymorphic objects (A | B)
18
+
-[Entity](https://dataclient.io/rest/api/Entity) - represents a single unique object (denormalized)
19
+
-[schema.Union(Entity)](https://dataclient.io/rest/api/Union) - polymorphic objects (A | B)
20
20
-`{[key:string]: Schema}` - immutable objects
21
21
-`schema.Invalidate(Entity)` - to delete an Entity
`Controller` is returned from `useController()`. It has: ctrl.fetch(), ctrl.fetchIfStale(), ctrl.expireAll(), ctrl.invalidate(), ctrl.invalidateAll(), ctrl.setResponse(), ctrl.set().
Copy file name to clipboardExpand all lines: .github/instructions/test.instructions.md
+10-5Lines changed: 10 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,11 @@ applyTo: '**/__tests__/*.ts*'
4
4
5
5
## Unit testing hooks
6
6
7
+
- Use [renderDataHook()](https://dataclient.io/docs/api/renderDataHook) to test hooks that use [@data-client/react](https://dataclient.io/docs) hooks.
8
+
-`renderDataHook()` inherits the options, and return values of `renderHook()` from [@testing-library/react](https://testing-library.com/docs/react-testing-library/api#renderhook).
**ALWAYS follow these patterns and refer to the official docs for edge cases. Prioritize code generation that is idiomatic, type-safe, and leverages automatic normalization/caching via schema definitions.**
93
+
**ALWAYS follow these patterns and refer to the official docs for edge cases.**
0 commit comments