Skip to content

Commit cc6b521

Browse files
committed
examples(react-fetch): show GitHub emojis
1 parent b9c2887 commit cc6b521

File tree

3 files changed

+45
-34
lines changed

3 files changed

+45
-34
lines changed

changelog.md

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,42 @@ editLink: false
44

55
# Changelog
66

7-
87
### [v0.8.0](https://github.com/compasjs/compas/releases/tag/v0.8.0)
98

109
#### Features
1110

12-
- feat(code-gen): generate RQ5 like object arguments while staying on RQ4 [`127699`](https://github.com/compasjs/compas/commit/127699362951d66d65b0c6abdc613fb9b420b035)
11+
- feat(code-gen): generate RQ5 like object arguments while staying on RQ4
12+
[`127699`](https://github.com/compasjs/compas/commit/127699362951d66d65b0c6abdc613fb9b420b035)
1313
- References [#2644](https://github.com/compasjs/compas/pull/2644)
14-
- feat(code-gen): support react-query v5 [`e4862f`](https://github.com/compasjs/compas/commit/e4862f36f2879bda72ef14983cf4cbee216b9b70)
14+
- feat(code-gen): support react-query v5
15+
[`e4862f`](https://github.com/compasjs/compas/commit/e4862f36f2879bda72ef14983cf4cbee216b9b70)
1516
- Closes [#2644](https://github.com/compasjs/compas/pull/2644)
1617

1718
#### Dependency updates
1819

19-
- build(deps): bump @aws-sdk/client-s3 from 3.428.0 to 3.436.0 ([#2907](https://github.com/compasjs/compas/pull/2907), [#2922](https://github.com/compasjs/compas/pull/2922))
20+
- build(deps): bump @aws-sdk/client-s3 from 3.428.0 to 3.436.0
21+
([#2907](https://github.com/compasjs/compas/pull/2907),
22+
[#2922](https://github.com/compasjs/compas/pull/2922))
2023
- [Release notes](https://github.com/aws/aws-sdk-js-v3/releases)
21-
- build(deps): bump @aws-sdk/lib-storage from 3.428.0 to 3.436.0 ([#2907](https://github.com/compasjs/compas/pull/2907), [#2922](https://github.com/compasjs/compas/pull/2922))
24+
- build(deps): bump @aws-sdk/lib-storage from 3.428.0 to 3.436.0
25+
([#2907](https://github.com/compasjs/compas/pull/2907),
26+
[#2922](https://github.com/compasjs/compas/pull/2922))
2227
- [Release notes](https://github.com/aws/aws-sdk-js-v3/releases)
23-
- build(deps): bump actions/setup-node from 3.8.1 to 4.0.0 ([#2919](https://github.com/compasjs/compas/pull/2919))
28+
- build(deps): bump actions/setup-node from 3.8.1 to 4.0.0
29+
([#2919](https://github.com/compasjs/compas/pull/2919))
2430
- Major version bump
2531
- [Release notes](https://github.com/actions/setup-node/releases)
26-
- build(deps): bump postgres from 3.4.0 to 3.4.1 ([#2922](https://github.com/compasjs/compas/pull/2922))
32+
- build(deps): bump postgres from 3.4.0 to 3.4.1
33+
([#2922](https://github.com/compasjs/compas/pull/2922))
2734
- [Release notes](https://github.com/porsager/postgres/releases)
28-
- build(deps): bump eslint from 8.51.0 to 8.52.0 ([#2922](https://github.com/compasjs/compas/pull/2922))
35+
- build(deps): bump eslint from 8.51.0 to 8.52.0
36+
([#2922](https://github.com/compasjs/compas/pull/2922))
2937
- [Release notes](https://github.com/eslint/eslint/releases)
30-
- build(deps): bump eslint-plugin-import from 2.28.1 to 2.29.0 ([#2922](https://github.com/compasjs/compas/pull/2922))
38+
- build(deps): bump eslint-plugin-import from 2.28.1 to 2.29.0
39+
([#2922](https://github.com/compasjs/compas/pull/2922))
3140
- [Release notes](https://github.com/import-js/eslint-plugin-import/releases)
32-
- build(deps): bump pino from 8.16.0 to 8.16.1 ([#2922](https://github.com/compasjs/compas/pull/2922))
41+
- build(deps): bump pino from 8.16.0 to 8.16.1
42+
([#2922](https://github.com/compasjs/compas/pull/2922))
3343
- [Release notes](https://github.com/pinojs/pino/releases)
3444

3545
### [v0.7.6](https://github.com/compasjs/compas/releases/tag/v0.7.6)
@@ -1004,4 +1014,4 @@ code-gen. Make sure that the API is updated before any consumer is.
10041014

10051015
See the
10061016
[history](https://github.com/compasjs/compas/blob/eaa62289e64516149a64b814ad36403c9316f313/changelog.md)
1007-
for earlier changelogs (< v0.0.249).
1017+
for earlier changelogs (< v0.0.249).

examples/react-fetch/scripts/generate.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
1-
import { Generator } from "@compas/code-gen";
1+
import { readFileSync } from "node:fs";
2+
import { Generator, loadApiStructureFromOpenAPI } from "@compas/code-gen";
3+
import { dirnameForModule, pathJoin } from "@compas/stdlib";
24

3-
const generator = new Generator();
4-
generator.addStructure(
5-
await (await fetch("https://ddv.tools/_compas/structure.json")).json(),
6-
);
5+
const generator = new Generator()
6+
.addStructure(
7+
loadApiStructureFromOpenAPI(
8+
"github",
9+
JSON.parse(
10+
readFileSync(
11+
pathJoin(
12+
dirnameForModule(import.meta),
13+
"../../../__fixtures__/code-gen/githubapi.json",
14+
),
15+
"utf-8",
16+
),
17+
),
18+
),
19+
)
20+
.selectGroups(["emojis"]);
721

822
generator.generate({
923
targetLanguage: "ts",

examples/react-fetch/src/App.tsx

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
11
import { keepPreviousData } from "@tanstack/react-query";
22
import { useEffect, useState } from "react";
33
import "./App.css";
4+
import { useEmojisEmojisGet } from "./generated/emojis/reactQueries.tsx";
45
import {
56
fetchWithBaseUrl,
67
setFetchFn,
78
} from "./generated/common/api-client.tsx";
8-
import { useDateConvertNumber } from "./generated/date/reactQueries.tsx";
99

1010
function App() {
11-
const [dateInput, setDateInput] = useState(1687000000000);
12-
1311
useEffect(() => {
14-
setFetchFn(fetchWithBaseUrl(fetch, "https://ddv.tools/"));
12+
setFetchFn(fetchWithBaseUrl(fetch, "https://api.github.com/"));
1513
}, []);
1614

17-
const { data } = useDateConvertNumber({
18-
value: dateInput,
19-
queryOptions: {
20-
placeholderData: keepPreviousData,
21-
},
22-
});
15+
const { data } = useEmojisEmojisGet({});
2316

2417
return (
2518
<>
2619
<h1>Compas + React + Fetch + React Query</h1>
2720
<div className="card">
28-
<span>Change the number:</span>
29-
<input
30-
type="number"
31-
onChange={(element) => setDateInput(Number(element.target.value))}
32-
value={dateInput}
33-
/>
34-
{data && <p>Date is {data.isoString}</p>}
35-
{!data && <p>Change the input to get a new value.</p>}
21+
{data && <p>GitHub supports {Object.keys(data).length} emojis.</p>}
22+
{!data && <p>Fetching emojis from GitHub</p>}
3623
</div>
3724

3825
<div className="card">

0 commit comments

Comments
 (0)