Skip to content

Commit b131885

Browse files
committed
docs: Query examples code refined
1 parent e38d618 commit b131885

File tree

1 file changed

+5
-11
lines changed

1 file changed

+5
-11
lines changed

docs/rest/api/Query.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ import { schema } from '@data-client/rest';
7272
import { useQuery, useFetch } from '@data-client/react';
7373
import { UserResource, User } from './resources/User';
7474

75-
const getUserCount = new schema.Query(
75+
const countUsers = new schema.Query(
7676
new schema.All(User),
7777
(entries, { isAdmin } = {}) => {
7878
if (isAdmin !== undefined)
@@ -83,8 +83,8 @@ const getUserCount = new schema.Query(
8383

8484
function UsersPage() {
8585
useFetch(UserResource.getList);
86-
const userCount = useQuery(getUserCount);
87-
const adminCount = useQuery(getUserCount, { isAdmin: true });
86+
const userCount = useQuery(countUsers);
87+
const adminCount = useQuery(countUsers, { isAdmin: true });
8888
if (userCount === undefined) return <div>No users in cache yet</div>;
8989
return (
9090
<div>
@@ -181,18 +181,13 @@ interface Props {
181181
```tsx title="TodoJoined"
182182
import { schema } from '@data-client/rest';
183183
import { useQuery, useFetch } from '@data-client/react';
184-
import { TodoResource, Todo } from './resources/Todo';
184+
import { TodoResource } from './resources/Todo';
185185
import { UserResource } from './resources/User';
186186
import TodoByUser from './TodoByUser';
187187

188188
const groupTodoByUser = new schema.Query(
189189
TodoResource.getList.schema,
190-
todos => {
191-
return Object.groupBy(todos, todo => todo.userId) as Record<
192-
number,
193-
Todo[]
194-
>;
195-
},
190+
todos => Object.groupBy(todos, todo => todo.userId),
196191
);
197192

198193
function TodosPage() {
@@ -213,7 +208,6 @@ function TodosPage() {
213208
</div>
214209
);
215210
}
216-
217211
render(<TodosPage />);
218212
```
219213

0 commit comments

Comments
 (0)