@soroush.design/cli 0.2.0-alpha.3 → 0.2.0-alpha.5

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 (250) hide show
  1. package/dist/bin.mjs +2 -15
  2. package/dist/index.d.mts +4 -4
  3. package/dist/index.mjs +1 -1
  4. package/dist/{io-Bybgct-f.mjs → io-CqI2BTaP.mjs} +430 -1032
  5. package/package.json +14 -5
  6. package/templates/astro/js/base/README.md +93 -0
  7. package/templates/astro/js/base/_gitignore +5 -0
  8. package/templates/astro/js/base/astro.config.mjs +23 -0
  9. package/templates/astro/js/base/src/components/About.jsx +24 -0
  10. package/templates/astro/js/base/src/components/Counter.jsx +26 -0
  11. package/templates/astro/js/base/src/components/Greeting.jsx +60 -0
  12. package/templates/astro/js/base/src/components/Header.jsx +99 -0
  13. package/templates/astro/js/base/src/components/Home.jsx +32 -0
  14. package/templates/astro/js/base/src/components/Home.test.jsx +39 -0
  15. package/templates/astro/js/base/src/components/NotFound.jsx +17 -0
  16. package/templates/astro/js/base/src/data/api.js +84 -0
  17. package/templates/astro/js/base/src/layouts/Layout.astro +52 -0
  18. package/templates/astro/js/base/src/pages/404.astro +12 -0
  19. package/templates/astro/js/base/src/pages/about.astro +12 -0
  20. package/templates/astro/js/base/src/pages/index.astro +23 -0
  21. package/templates/astro/js/base/src/theme/Island.jsx +89 -0
  22. package/templates/astro/js/base/src/theme/scheme.js +32 -0
  23. package/templates/astro/js/base/vitest.config.js +12 -0
  24. package/templates/astro/js/sample-data/src/components/ItemDetails.jsx +64 -0
  25. package/templates/astro/js/sample-data/src/components/ItemList.jsx +100 -0
  26. package/templates/astro/js/sample-data/src/components/StatusChip.jsx +8 -0
  27. package/templates/astro/js/sample-data/src/data/items.js +65 -0
  28. package/templates/astro/js/sample-data/src/pages/items/[id].astro +37 -0
  29. package/templates/astro/js/sample-data/src/pages/items/index.astro +20 -0
  30. package/templates/astro/js/with/jotai/src/components/Counter.jsx +26 -0
  31. package/templates/astro/js/with/jotai/src/state/counter.js +4 -0
  32. package/templates/astro/js/with/msw/_env +3 -0
  33. package/templates/astro/js/with/msw/src/mocks/browser.js +5 -0
  34. package/templates/astro/js/with/msw/src/mocks/handlers.js +24 -0
  35. package/templates/astro/js/with/msw/src/mocks/server.js +5 -0
  36. package/templates/astro/js/with/msw/src/mocks/setupTests.js +7 -0
  37. package/templates/astro/js/with/msw/src/mocks/start.js +14 -0
  38. package/templates/astro/js/with/react-hook-form/src/components/Form.jsx +313 -0
  39. package/templates/astro/js/with/react-hook-form/src/pages/form.astro +8 -0
  40. package/templates/astro/js/with/redux-toolkit/src/components/Counter.jsx +27 -0
  41. package/templates/astro/js/with/redux-toolkit/src/state/store.js +18 -0
  42. package/templates/astro/js/with/tanstack-query/src/data/queryClient.js +13 -0
  43. package/templates/astro/js/with/zustand/src/components/Counter.jsx +24 -0
  44. package/templates/astro/js/with/zustand/src/state/counter.js +14 -0
  45. package/templates/astro/ts/base/README.md +93 -0
  46. package/templates/astro/ts/base/_gitignore +5 -0
  47. package/templates/astro/ts/base/astro.config.mjs +23 -0
  48. package/templates/astro/ts/base/src/components/About.tsx +24 -0
  49. package/templates/astro/ts/base/src/components/Counter.tsx +26 -0
  50. package/templates/astro/ts/base/src/components/Greeting.tsx +61 -0
  51. package/templates/astro/ts/base/src/components/Header.tsx +99 -0
  52. package/templates/astro/ts/base/src/components/Home.test.tsx +39 -0
  53. package/templates/astro/ts/base/src/components/Home.tsx +33 -0
  54. package/templates/astro/ts/base/src/components/NotFound.tsx +17 -0
  55. package/templates/astro/ts/base/src/data/api.ts +92 -0
  56. package/templates/astro/ts/base/src/layouts/Layout.astro +52 -0
  57. package/templates/astro/ts/base/src/pages/404.astro +12 -0
  58. package/templates/astro/ts/base/src/pages/about.astro +12 -0
  59. package/templates/astro/ts/base/src/pages/index.astro +23 -0
  60. package/templates/astro/ts/base/src/theme/Island.tsx +90 -0
  61. package/templates/astro/ts/base/src/theme/scheme.ts +34 -0
  62. package/templates/astro/ts/base/tsconfig.json +9 -0
  63. package/templates/astro/ts/base/vitest.config.ts +12 -0
  64. package/templates/astro/ts/sample-data/src/components/ItemDetails.tsx +65 -0
  65. package/templates/astro/ts/sample-data/src/components/ItemList.tsx +109 -0
  66. package/templates/astro/ts/sample-data/src/components/StatusChip.tsx +9 -0
  67. package/templates/astro/ts/sample-data/src/data/items.ts +71 -0
  68. package/templates/astro/ts/sample-data/src/pages/items/[id].astro +39 -0
  69. package/templates/astro/ts/sample-data/src/pages/items/index.astro +20 -0
  70. package/templates/astro/ts/with/jotai/src/components/Counter.tsx +26 -0
  71. package/templates/astro/ts/with/jotai/src/state/counter.ts +4 -0
  72. package/templates/astro/ts/with/msw/_env +3 -0
  73. package/templates/astro/ts/with/msw/src/mocks/browser.ts +5 -0
  74. package/templates/astro/ts/with/msw/src/mocks/handlers.ts +24 -0
  75. package/templates/astro/ts/with/msw/src/mocks/server.ts +5 -0
  76. package/templates/astro/ts/with/msw/src/mocks/setupTests.ts +7 -0
  77. package/templates/astro/ts/with/msw/src/mocks/start.ts +14 -0
  78. package/templates/astro/ts/with/react-hook-form/src/components/Form.tsx +317 -0
  79. package/templates/astro/ts/with/react-hook-form/src/pages/form.astro +8 -0
  80. package/templates/astro/ts/with/redux-toolkit/src/components/Counter.tsx +27 -0
  81. package/templates/astro/ts/with/redux-toolkit/src/state/store.ts +19 -0
  82. package/templates/astro/ts/with/tanstack-query/src/data/queryClient.ts +13 -0
  83. package/templates/astro/ts/with/zustand/src/components/Counter.tsx +24 -0
  84. package/templates/astro/ts/with/zustand/src/state/counter.ts +19 -0
  85. package/templates/react-router/js/base/README.md +67 -0
  86. package/templates/react-router/js/base/_gitignore +4 -0
  87. package/templates/react-router/js/base/index.html +12 -0
  88. package/templates/react-router/js/base/src/components/RouterLink.jsx +12 -0
  89. package/templates/react-router/js/base/src/data/api.js +76 -0
  90. package/templates/react-router/js/base/src/main.jsx +38 -0
  91. package/templates/react-router/js/base/src/pages/ErrorPage.jsx +14 -0
  92. package/templates/react-router/js/base/src/pages/Layout.jsx +141 -0
  93. package/templates/react-router/js/base/src/pages/about/Page.jsx +14 -0
  94. package/templates/react-router/js/base/src/pages/index/Counter.jsx +18 -0
  95. package/templates/react-router/js/base/src/pages/index/Greeting.jsx +48 -0
  96. package/templates/react-router/js/base/src/pages/index/Page.jsx +29 -0
  97. package/templates/react-router/js/base/src/pages/index/Page.test.jsx +61 -0
  98. package/templates/react-router/js/base/src/routes.jsx +46 -0
  99. package/templates/react-router/js/base/vite.config.js +13 -0
  100. package/templates/react-router/js/base/vitest.config.js +13 -0
  101. package/templates/react-router/js/sample-data/src/data/items.js +55 -0
  102. package/templates/react-router/js/sample-data/src/pages/item/Page.jsx +49 -0
  103. package/templates/react-router/js/sample-data/src/pages/item/loader.js +14 -0
  104. package/templates/react-router/js/sample-data/src/pages/items/Page.jsx +48 -0
  105. package/templates/react-router/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
  106. package/templates/react-router/js/sample-data/src/pages/items/loader.js +11 -0
  107. package/templates/react-router/js/with/jotai/src/pages/index/Counter.jsx +19 -0
  108. package/templates/react-router/js/with/jotai/src/state/counter.js +4 -0
  109. package/templates/react-router/js/with/jotai/src/state/scheme.js +4 -0
  110. package/templates/react-router/js/with/msw/_env +3 -0
  111. package/templates/react-router/js/with/msw/src/mocks/browser.js +5 -0
  112. package/templates/react-router/js/with/msw/src/mocks/handlers.js +24 -0
  113. package/templates/react-router/js/with/msw/src/mocks/server.js +5 -0
  114. package/templates/react-router/js/with/msw/src/mocks/setupTests.js +7 -0
  115. package/templates/react-router/js/with/msw/src/mocks/start.js +10 -0
  116. package/templates/react-router/js/with/react-hook-form/src/pages/form/Page.jsx +294 -0
  117. package/templates/react-router/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
  118. package/templates/react-router/js/with/redux-toolkit/src/state/store.js +27 -0
  119. package/templates/react-router/js/with/zustand/src/pages/index/Counter.jsx +17 -0
  120. package/templates/react-router/js/with/zustand/src/state/counter.js +14 -0
  121. package/templates/react-router/js/with/zustand/src/state/scheme.js +14 -0
  122. package/templates/react-router/ts/base/README.md +67 -0
  123. package/templates/react-router/ts/base/_gitignore +4 -0
  124. package/templates/react-router/ts/base/index.html +12 -0
  125. package/templates/react-router/ts/base/src/components/RouterLink.tsx +12 -0
  126. package/templates/react-router/ts/base/src/data/api.ts +84 -0
  127. package/templates/react-router/ts/base/src/main.tsx +38 -0
  128. package/templates/react-router/ts/base/src/pages/ErrorPage.tsx +14 -0
  129. package/templates/react-router/ts/base/src/pages/Layout.tsx +141 -0
  130. package/templates/react-router/ts/base/src/pages/about/Page.tsx +14 -0
  131. package/templates/react-router/ts/base/src/pages/index/Counter.tsx +18 -0
  132. package/templates/react-router/ts/base/src/pages/index/Greeting.tsx +49 -0
  133. package/templates/react-router/ts/base/src/pages/index/Page.test.tsx +61 -0
  134. package/templates/react-router/ts/base/src/pages/index/Page.tsx +29 -0
  135. package/templates/react-router/ts/base/src/routes.tsx +47 -0
  136. package/templates/react-router/ts/base/tsconfig.json +18 -0
  137. package/templates/react-router/ts/base/vite.config.ts +13 -0
  138. package/templates/react-router/ts/base/vitest.config.ts +13 -0
  139. package/templates/react-router/ts/sample-data/src/data/items.ts +61 -0
  140. package/templates/react-router/ts/sample-data/src/pages/item/Page.tsx +50 -0
  141. package/templates/react-router/ts/sample-data/src/pages/item/loader.ts +14 -0
  142. package/templates/react-router/ts/sample-data/src/pages/items/Page.tsx +49 -0
  143. package/templates/react-router/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
  144. package/templates/react-router/ts/sample-data/src/pages/items/loader.ts +11 -0
  145. package/templates/react-router/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
  146. package/templates/react-router/ts/with/jotai/src/state/counter.ts +4 -0
  147. package/templates/react-router/ts/with/jotai/src/state/scheme.ts +4 -0
  148. package/templates/react-router/ts/with/msw/_env +3 -0
  149. package/templates/react-router/ts/with/msw/src/mocks/browser.ts +5 -0
  150. package/templates/react-router/ts/with/msw/src/mocks/handlers.ts +24 -0
  151. package/templates/react-router/ts/with/msw/src/mocks/server.ts +5 -0
  152. package/templates/react-router/ts/with/msw/src/mocks/setupTests.ts +7 -0
  153. package/templates/react-router/ts/with/msw/src/mocks/start.ts +10 -0
  154. package/templates/react-router/ts/with/react-hook-form/src/pages/form/Page.tsx +298 -0
  155. package/templates/react-router/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
  156. package/templates/react-router/ts/with/redux-toolkit/src/state/store.ts +29 -0
  157. package/templates/react-router/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
  158. package/templates/react-router/ts/with/zustand/src/state/counter.ts +19 -0
  159. package/templates/react-router/ts/with/zustand/src/state/scheme.ts +19 -0
  160. package/templates/templates.md +67 -0
  161. package/templates/vike/js/base/README.md +83 -0
  162. package/templates/vike/js/base/_gitignore +4 -0
  163. package/templates/vike/js/base/src/data/api.js +76 -0
  164. package/templates/vike/js/base/src/pages/+Layout.jsx +183 -0
  165. package/templates/vike/js/base/src/pages/+config.js +12 -0
  166. package/templates/vike/js/base/src/pages/+onRenderClient.jsx +39 -0
  167. package/templates/vike/js/base/src/pages/+onRenderHtml.jsx +27 -0
  168. package/templates/vike/js/base/src/pages/PageShell.jsx +47 -0
  169. package/templates/vike/js/base/src/pages/_error/+Page.jsx +14 -0
  170. package/templates/vike/js/base/src/pages/about/+Page.jsx +14 -0
  171. package/templates/vike/js/base/src/pages/index/+Page.jsx +33 -0
  172. package/templates/vike/js/base/src/pages/index/Counter.jsx +20 -0
  173. package/templates/vike/js/base/src/pages/index/Greeting.jsx +48 -0
  174. package/templates/vike/js/base/src/pages/index/Page.test.jsx +67 -0
  175. package/templates/vike/js/base/src/pages/usePageContext.jsx +20 -0
  176. package/templates/vike/js/base/vite.config.js +14 -0
  177. package/templates/vike/js/base/vitest.config.js +13 -0
  178. package/templates/vike/js/sample-data/src/data/items.js +58 -0
  179. package/templates/vike/js/sample-data/src/pages/items/+Page.jsx +49 -0
  180. package/templates/vike/js/sample-data/src/pages/items/+data.js +26 -0
  181. package/templates/vike/js/sample-data/src/pages/items/@id/+Page.jsx +40 -0
  182. package/templates/vike/js/sample-data/src/pages/items/@id/+data.js +33 -0
  183. package/templates/vike/js/sample-data/src/pages/items/@id/+onBeforePrerenderStart.js +8 -0
  184. package/templates/vike/js/sample-data/src/pages/items/StatusChip.jsx +8 -0
  185. package/templates/vike/js/ssg/src/pages/+config.js +11 -0
  186. package/templates/vike/js/ssg/src/pages/about/+Page.jsx +13 -0
  187. package/templates/vike/js/ssr/src/pages/+config.js +12 -0
  188. package/templates/vike/js/ssr/src/pages/+onRenderHtml.jsx +27 -0
  189. package/templates/vike/js/ssr/src/pages/about/+Page.jsx +14 -0
  190. package/templates/vike/js/with/jotai/src/pages/index/Counter.jsx +19 -0
  191. package/templates/vike/js/with/jotai/src/state/counter.js +4 -0
  192. package/templates/vike/js/with/jotai/src/state/scheme.js +4 -0
  193. package/templates/vike/js/with/msw/_env +3 -0
  194. package/templates/vike/js/with/msw/src/mocks/browser.js +5 -0
  195. package/templates/vike/js/with/msw/src/mocks/handlers.js +24 -0
  196. package/templates/vike/js/with/msw/src/mocks/server.js +5 -0
  197. package/templates/vike/js/with/msw/src/mocks/setupTests.js +7 -0
  198. package/templates/vike/js/with/msw/src/mocks/start.js +10 -0
  199. package/templates/vike/js/with/react-hook-form/src/pages/form/+Page.jsx +294 -0
  200. package/templates/vike/js/with/redux-toolkit/src/pages/index/Counter.jsx +20 -0
  201. package/templates/vike/js/with/redux-toolkit/src/state/store.js +27 -0
  202. package/templates/vike/js/with/zustand/src/pages/index/Counter.jsx +17 -0
  203. package/templates/vike/js/with/zustand/src/state/counter.js +14 -0
  204. package/templates/vike/js/with/zustand/src/state/scheme.js +14 -0
  205. package/templates/vike/ts/base/README.md +83 -0
  206. package/templates/vike/ts/base/_gitignore +4 -0
  207. package/templates/vike/ts/base/src/data/api.ts +84 -0
  208. package/templates/vike/ts/base/src/pages/+Layout.tsx +184 -0
  209. package/templates/vike/ts/base/src/pages/+config.ts +14 -0
  210. package/templates/vike/ts/base/src/pages/+onRenderClient.tsx +41 -0
  211. package/templates/vike/ts/base/src/pages/+onRenderHtml.tsx +28 -0
  212. package/templates/vike/ts/base/src/pages/PageShell.tsx +48 -0
  213. package/templates/vike/ts/base/src/pages/_error/+Page.tsx +14 -0
  214. package/templates/vike/ts/base/src/pages/about/+Page.tsx +14 -0
  215. package/templates/vike/ts/base/src/pages/index/+Page.tsx +33 -0
  216. package/templates/vike/ts/base/src/pages/index/Counter.tsx +20 -0
  217. package/templates/vike/ts/base/src/pages/index/Greeting.tsx +49 -0
  218. package/templates/vike/ts/base/src/pages/index/Page.test.tsx +67 -0
  219. package/templates/vike/ts/base/src/pages/usePageContext.tsx +27 -0
  220. package/templates/vike/ts/base/src/vike.d.ts +20 -0
  221. package/templates/vike/ts/base/tsconfig.json +18 -0
  222. package/templates/vike/ts/base/vite.config.ts +14 -0
  223. package/templates/vike/ts/base/vitest.config.ts +13 -0
  224. package/templates/vike/ts/sample-data/src/data/items.ts +64 -0
  225. package/templates/vike/ts/sample-data/src/pages/items/+Page.tsx +50 -0
  226. package/templates/vike/ts/sample-data/src/pages/items/+data.ts +28 -0
  227. package/templates/vike/ts/sample-data/src/pages/items/@id/+Page.tsx +41 -0
  228. package/templates/vike/ts/sample-data/src/pages/items/@id/+data.ts +37 -0
  229. package/templates/vike/ts/sample-data/src/pages/items/@id/+onBeforePrerenderStart.ts +8 -0
  230. package/templates/vike/ts/sample-data/src/pages/items/StatusChip.tsx +9 -0
  231. package/templates/vike/ts/ssg/src/pages/+config.ts +13 -0
  232. package/templates/vike/ts/ssg/src/pages/about/+Page.tsx +13 -0
  233. package/templates/vike/ts/ssr/src/pages/+config.ts +14 -0
  234. package/templates/vike/ts/ssr/src/pages/+onRenderHtml.tsx +28 -0
  235. package/templates/vike/ts/ssr/src/pages/about/+Page.tsx +14 -0
  236. package/templates/vike/ts/with/jotai/src/pages/index/Counter.tsx +19 -0
  237. package/templates/vike/ts/with/jotai/src/state/counter.ts +4 -0
  238. package/templates/vike/ts/with/jotai/src/state/scheme.ts +4 -0
  239. package/templates/vike/ts/with/msw/_env +3 -0
  240. package/templates/vike/ts/with/msw/src/mocks/browser.ts +5 -0
  241. package/templates/vike/ts/with/msw/src/mocks/handlers.ts +24 -0
  242. package/templates/vike/ts/with/msw/src/mocks/server.ts +5 -0
  243. package/templates/vike/ts/with/msw/src/mocks/setupTests.ts +7 -0
  244. package/templates/vike/ts/with/msw/src/mocks/start.ts +10 -0
  245. package/templates/vike/ts/with/react-hook-form/src/pages/form/+Page.tsx +298 -0
  246. package/templates/vike/ts/with/redux-toolkit/src/pages/index/Counter.tsx +20 -0
  247. package/templates/vike/ts/with/redux-toolkit/src/state/store.ts +29 -0
  248. package/templates/vike/ts/with/zustand/src/pages/index/Counter.tsx +17 -0
  249. package/templates/vike/ts/with/zustand/src/state/counter.ts +19 -0
  250. package/templates/vike/ts/with/zustand/src/state/scheme.ts +19 -0
@@ -0,0 +1,14 @@
1
+ import { create } from 'zustand'
2
+
3
+ /** The home page's count: a zustand store, which any component can read. */
4
+ // @if ts
5
+ export const useCounter = create()((set) => ({
6
+ count: 0,
7
+ increment: () => set((state) => ({ count: state.count + 1 })),
8
+ }))
9
+ // @else
10
+ export const useCounter = create((set) => ({
11
+ count: 0,
12
+ increment: () => set((state) => ({ count: state.count + 1 })),
13
+ }))
14
+ // @endif
@@ -0,0 +1,14 @@
1
+ import { create } from 'zustand'
2
+
3
+ /** The color scheme the app is drawn in: a zustand store, which any component can read. */
4
+ // @if ts
5
+ export const useScheme = create()((set) => ({
6
+ scheme: '__SCHEME__',
7
+ setScheme: (scheme) => set({ scheme }),
8
+ }))
9
+ // @else
10
+ export const useScheme = create((set) => ({
11
+ scheme: '__SCHEME__',
12
+ setScheme: (scheme) => set({ scheme }),
13
+ }))
14
+ // @endif
@@ -0,0 +1,83 @@
1
+ # __TITLE__
2
+
3
+ A [Vike](https://vike.dev) app on the [@soroush.tech design system](https://docs.soroush.tech):
4
+ <!-- @if isomorphic -->
5
+ prerendered at build time with its styles in the HTML, then moving between pages with no reload.
6
+ <!-- @elif ssr -->
7
+ every page rendered on the server, on each request, with its styles in the HTML, then moving between pages with no reload.
8
+ <!-- @else -->
9
+ every page prerendered to HTML at build time, with its styles, and no JavaScript in the browser.
10
+ <!-- @endif -->
11
+
12
+ - `npm run dev` starts it, `npm run build` builds it, and `npm run preview` serves the build.
13
+ <!-- @if ssr -->
14
+ - `npm start` runs the server the build wrote, on `PORT` (3000 by default), on any Node host.
15
+ <!-- @endif -->
16
+ - `src/pages/` holds the pages: a folder per route, each with its `+Page`.
17
+ - `src/pages/+Layout.tsx` is the frame every page renders in, inside the app's providers.
18
+ - `src/theme/themes.ts` holds the light and the dark theme: make them your own.
19
+ <!-- @if isomorphic -->
20
+ - In `src/pages/`, `+onRenderHtml` and `+onRenderClient` render the pages, with the styles each page uses in its HTML.
21
+ <!-- @elif ssr -->
22
+ - In `src/pages/`, `+onRenderHtml` renders each page on the server and `+onRenderClient` takes it over in the browser, with the styles each page uses in its HTML.
23
+ <!-- @else -->
24
+ - In `src/pages/`, `+onRenderHtml` renders the pages to HTML, with the styles each page uses.
25
+ <!-- @endif -->
26
+ <!-- @if sample-data -->
27
+ - `src/pages/items/` lists the sample items of `src/data/items.ts`, with a page for each.
28
+ <!-- @if ssr -->
29
+ Their `+data` hooks read the data on each request: make them fetch your own.
30
+ <!-- @else -->
31
+ Their `+data` hooks read the data at build time: make them fetch your own.
32
+ <!-- @endif -->
33
+ <!-- @endif -->
34
+ <!-- @if !ssg && !zustand && !jotai && !redux-toolkit -->
35
+ - `src/pages/index/Counter.tsx` counts the presses of its button, in its own state.
36
+ <!-- @endif -->
37
+ <!-- @if tanstack-query && react-hook-form && sample-data -->
38
+ - [TanStack Query](https://tanstack.com/query): the query client lives in `+Layout`. The home page's `Greeting` reads `src/data/api.ts` with a query, and the form sends its values with a mutation. The items pages start on their build-time data, then query it in the browser.
39
+ <!-- @elif tanstack-query && react-hook-form -->
40
+ - [TanStack Query](https://tanstack.com/query): the query client lives in `+Layout`. The home page's `Greeting` reads `src/data/api.ts` with a query, and the form sends its values with a mutation.
41
+ <!-- @elif tanstack-query && sample-data -->
42
+ - [TanStack Query](https://tanstack.com/query): the query client lives in `+Layout`. The home page's `Greeting` reads `src/data/api.ts` with a query. The items pages start on their build-time data, then query it in the browser.
43
+ <!-- @elif tanstack-query -->
44
+ - [TanStack Query](https://tanstack.com/query): the query client lives in `+Layout`. The home page's `Greeting` reads `src/data/api.ts` with a query.
45
+ <!-- @endif -->
46
+ <!-- @if swr && react-hook-form && sample-data -->
47
+ - [SWR](https://swr.vercel.app): the home page's `Greeting` reads `src/data/api.ts` with SWR, and the form sends its values with a mutation. The items pages start on their build-time data, then fetch it in the browser.
48
+ <!-- @elif swr && react-hook-form -->
49
+ - [SWR](https://swr.vercel.app): the home page's `Greeting` reads `src/data/api.ts` with SWR, and the form sends its values with a mutation.
50
+ <!-- @elif swr && sample-data -->
51
+ - [SWR](https://swr.vercel.app): the home page's `Greeting` reads `src/data/api.ts` with SWR. The items pages start on their build-time data, then fetch it in the browser.
52
+ <!-- @elif swr -->
53
+ - [SWR](https://swr.vercel.app): the home page's `Greeting` reads `src/data/api.ts` with SWR.
54
+ <!-- @endif -->
55
+ <!-- @if msw && react-hook-form && sample-data -->
56
+ - [msw](https://mswjs.io): `src/mocks/handlers.ts` is a mock API, which answers the greeting, the form, the sample items in the browser while `VITE_MSW` in `.env` is true.
57
+ <!-- @elif msw && react-hook-form -->
58
+ - [msw](https://mswjs.io): `src/mocks/handlers.ts` is a mock API, which answers the greeting, the form in the browser while `VITE_MSW` in `.env` is true.
59
+ <!-- @elif msw && sample-data -->
60
+ - [msw](https://mswjs.io): `src/mocks/handlers.ts` is a mock API, which answers the greeting, the sample items in the browser while `VITE_MSW` in `.env` is true.
61
+ <!-- @elif msw -->
62
+ - [msw](https://mswjs.io): `src/mocks/handlers.ts` is a mock API, which answers the greeting in the browser while `VITE_MSW` in `.env` is true.
63
+ <!-- @endif -->
64
+ <!-- @if zustand -->
65
+ - [zustand](https://zustand.docs.pmnd.rs): `src/state/scheme.ts` holds the color scheme and `src/state/counter.ts` the home page's count, in stores.
66
+ <!-- @elif jotai -->
67
+ - [Jotai](https://jotai.org): `src/state/scheme.ts` holds the color scheme and `src/state/counter.ts` the home page's count, in atoms.
68
+ <!-- @elif redux-toolkit -->
69
+ - [Redux Toolkit](https://redux-toolkit.js.org): `src/state/store.ts` holds the color scheme and the home page's count, in slices of the store `PageShell` provides.
70
+ <!-- @endif -->
71
+ <!-- @if react-hook-form -->
72
+ - [React Hook Form](https://react-hook-form.com) and [Zod](https://zod.dev): `/form` is a form whose values a Zod schema checks.
73
+ <!-- @endif -->
74
+ <!-- @if ssg -->
75
+ - [Vitest](https://vitest.dev) and [Testing Library](https://testing-library.com): `npm run test` runs `src/pages/index/Page.test.tsx`, which checks the title.
76
+ <!-- @elif msw -->
77
+ - [Vitest](https://vitest.dev) and [Testing Library](https://testing-library.com): `npm run test` runs `src/pages/index/Page.test.tsx`, which checks the title, the counter and the greeting, which msw's Node server, `src/mocks/server.ts`, answers.
78
+ <!-- @else -->
79
+ - [Vitest](https://vitest.dev) and [Testing Library](https://testing-library.com): `npm run test` runs `src/pages/index/Page.test.tsx`, which checks the title and the counter.
80
+ <!-- @endif -->
81
+
82
+ Fonts: the theme names Space Grotesk and JetBrains Mono, and does not load them. See
83
+ https://docs.soroush.tech/design-system/getting-started/installation/#fonts
@@ -0,0 +1,4 @@
1
+ node_modules/
2
+ dist/
3
+ *.log
4
+ .DS_Store
@@ -0,0 +1,84 @@
1
+ // @if tanstack-query || swr || msw
2
+ // @if ts && sample-data && msw && (tanstack-query || swr)
3
+ import type { Item } from './items'
4
+
5
+ // @elif sample-data && !msw && (tanstack-query || swr)
6
+ import { items } from './items'
7
+
8
+ // @endif
9
+ // @if ts
10
+ /** What the API says to the app. */
11
+ export interface Greeting {
12
+ message: string
13
+ }
14
+ // @if react-hook-form
15
+
16
+ /** What the form sends. */
17
+ export interface Message {
18
+ name: string
19
+ email: string
20
+ }
21
+ // @endif
22
+
23
+ // @endif
24
+ // @if msw
25
+ /** A greeting, from the API: while VITE_MSW is true, the mock API of src/mocks answers. */
26
+ export async function fetchGreeting(): Promise<Greeting> {
27
+ const response = await fetch('/api/greeting')
28
+ if (!response.ok) throw new Error(`GET /api/greeting answered ${response.status}`)
29
+ return response.json()
30
+ }
31
+ // @else
32
+ /** A greeting, as an API would answer: make it fetch from yours. */
33
+ export function fetchGreeting(): Promise<Greeting> {
34
+ return Promise.resolve({ message: 'Hello from src/data/api: make it fetch from your API.' })
35
+ }
36
+ // @endif
37
+ // @if react-hook-form && msw
38
+
39
+ /** Sends the form's values to the API, which answers what it made of them. */
40
+ export async function sendMessage(message: Message): Promise<Greeting> {
41
+ const response = await fetch('/api/messages', {
42
+ method: 'POST',
43
+ headers: { 'Content-Type': 'application/json' },
44
+ body: JSON.stringify(message),
45
+ })
46
+ if (!response.ok) throw new Error(`POST /api/messages answered ${response.status}`)
47
+ return response.json()
48
+ }
49
+ // @elif react-hook-form
50
+
51
+ /** Sends the form's values, as an API would take them: make it post to yours. */
52
+ export function sendMessage(message: Message): Promise<Greeting> {
53
+ return Promise.resolve({ message: `Thanks, ${message.name}: your message was sent.` })
54
+ }
55
+ // @endif
56
+ // @if sample-data && msw && (tanstack-query || swr)
57
+
58
+ /** The items, from the API: while VITE_MSW is true, the mock API of src/mocks answers. */
59
+ export async function fetchItems(): Promise<Pick<Item, 'id' | 'title' | 'status'>[]> {
60
+ const response = await fetch('/api/items')
61
+ if (!response.ok) throw new Error(`GET /api/items answered ${response.status}`)
62
+ return response.json()
63
+ }
64
+
65
+ /** One item, from the API. */
66
+ export async function fetchItem(id: string): Promise<Item> {
67
+ const response = await fetch(`/api/items/${id}`)
68
+ if (!response.ok) throw new Error(`GET /api/items/${id} answered ${response.status}`)
69
+ return response.json()
70
+ }
71
+ // @elif sample-data && (tanstack-query || swr)
72
+
73
+ /** The items, as an API would answer: make it fetch from yours. */
74
+ export function fetchItems() {
75
+ return Promise.resolve(items.map(({ id, title, status }) => ({ id, title, status })))
76
+ }
77
+
78
+ /** One item, as an API would answer: make it fetch from yours. */
79
+ export function fetchItem(id: string) {
80
+ const item = items.find((candidate) => candidate.id === id)
81
+ return item ? Promise.resolve(item) : Promise.reject(new Error(`There is no item ${id}.`))
82
+ }
83
+ // @endif
84
+ // @endif
@@ -0,0 +1,184 @@
1
+ // @if !ssg && (tanstack-query || (!zustand && !jotai && !redux-toolkit))
2
+ import { useState, type ReactNode } from 'react'
3
+ // @else
4
+ import type { ReactNode } from 'react'
5
+ // @endif
6
+ // @if !ssg
7
+ import { Button } from '@soroush.tech/design-system/Button'
8
+ // @endif
9
+ import { Flex } from '@soroush.tech/design-system/Flex'
10
+ import { Link } from '@soroush.tech/design-system/Link'
11
+ import { Typography } from '@soroush.tech/design-system/Typography'
12
+ import { View } from '@soroush.tech/design-system/View'
13
+ // @if tanstack-query
14
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
15
+ // @endif
16
+ // @if zustand
17
+ import { useScheme } from '../state/scheme'
18
+ // @elif jotai
19
+ import { useAtom } from 'jotai'
20
+ import { schemeAtom } from '../state/scheme'
21
+ // @elif redux-toolkit
22
+ import { useDispatch, useSelector } from 'react-redux'
23
+ import { schemeChanged, type RootState } from '../state/store'
24
+ // @endif
25
+ import { Providers } from '../theme/Providers'
26
+
27
+ /**
28
+ // @if ssg
29
+ * The frame every page renders in, inside the app's providers. A page has no JavaScript in the
30
+ * browser, so it is drawn in the default scheme, which src/theme/Providers.ts sets.
31
+ // @elif zustand || jotai
32
+ * The frame every page renders in. The app's providers live here, in the app itself, so the
33
+ * scheme, held in src/state/scheme.ts, can switch the theme.
34
+ // @elif redux-toolkit
35
+ * The frame every page renders in. The app's providers live here, in the app itself, so the
36
+ * scheme, held in src/state/store.ts, can switch the theme.
37
+ // @else
38
+ * The frame every page renders in. The app's providers live here, in the app itself, so the
39
+ * scheme it holds can switch the theme.
40
+ // @endif
41
+ */
42
+ export default function Layout({ children }: { readonly children: ReactNode }) {
43
+ // @if tanstack-query
44
+ const [queryClient] = useState(() => new QueryClient())
45
+ // @endif
46
+ // @if zustand
47
+ const { scheme, setScheme } = useScheme()
48
+ // @elif jotai
49
+ const [scheme, setScheme] = useAtom(schemeAtom)
50
+ // @elif redux-toolkit
51
+ const scheme = useSelector((state: RootState) => state.scheme)
52
+ const dispatch = useDispatch()
53
+ const setScheme = (next: 'light' | 'dark') => dispatch(schemeChanged(next))
54
+ // @elif !ssg
55
+ const [scheme, setScheme] = useState<'light' | 'dark'>('__SCHEME__')
56
+ // @endif
57
+ // @if !ssg
58
+ const otherScheme = scheme === 'light' ? 'dark' : 'light'
59
+ // @endif
60
+ // @if ssg
61
+ return (
62
+ <Providers>
63
+ <Flex
64
+ as="header"
65
+ flexDirection="row"
66
+ alignItems="center"
67
+ justifyContent="space-between"
68
+ gap={2}
69
+ px={3}
70
+ py={2}
71
+ bg="paper"
72
+ >
73
+ <Typography variant="h6" as="span">
74
+ __TITLE__
75
+ </Typography>
76
+ <Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
77
+ <Link href="/" underline="hover">
78
+ Home
79
+ </Link>
80
+ <Link href="/about" underline="hover">
81
+ About
82
+ </Link>
83
+ {/* @if sample-data */}
84
+ <Link href="/items" underline="hover">
85
+ Items
86
+ </Link>
87
+ {/* @endif */}
88
+ </Flex>
89
+ </Flex>
90
+ <View as="main" px={3} py={4}>
91
+ {children}
92
+ </View>
93
+ </Providers>
94
+ )
95
+ // @elif tanstack-query
96
+ return (
97
+ <QueryClientProvider client={queryClient}>
98
+ <Providers scheme={scheme}>
99
+ <Flex
100
+ as="header"
101
+ flexDirection="row"
102
+ alignItems="center"
103
+ justifyContent="space-between"
104
+ gap={2}
105
+ px={3}
106
+ py={2}
107
+ bg="paper"
108
+ >
109
+ <Typography variant="h6" as="span">
110
+ __TITLE__
111
+ </Typography>
112
+ <Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
113
+ <Link href="/" underline="hover">
114
+ Home
115
+ </Link>
116
+ <Link href="/about" underline="hover">
117
+ About
118
+ </Link>
119
+ {/* @if sample-data */}
120
+ <Link href="/items" underline="hover">
121
+ Items
122
+ </Link>
123
+ {/* @endif */}
124
+ {/* @if react-hook-form */}
125
+ <Link href="/form" underline="hover">
126
+ Form
127
+ </Link>
128
+ {/* @endif */}
129
+ <Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
130
+ {otherScheme}
131
+ </Button>
132
+ </Flex>
133
+ </Flex>
134
+ <View as="main" px={3} py={4}>
135
+ {children}
136
+ </View>
137
+ </Providers>
138
+ </QueryClientProvider>
139
+ )
140
+ // @else
141
+ return (
142
+ <Providers scheme={scheme}>
143
+ <Flex
144
+ as="header"
145
+ flexDirection="row"
146
+ alignItems="center"
147
+ justifyContent="space-between"
148
+ gap={2}
149
+ px={3}
150
+ py={2}
151
+ bg="paper"
152
+ >
153
+ <Typography variant="h6" as="span">
154
+ __TITLE__
155
+ </Typography>
156
+ <Flex as="nav" flexDirection="row" alignItems="center" gap={2}>
157
+ <Link href="/" underline="hover">
158
+ Home
159
+ </Link>
160
+ <Link href="/about" underline="hover">
161
+ About
162
+ </Link>
163
+ {/* @if sample-data */}
164
+ <Link href="/items" underline="hover">
165
+ Items
166
+ </Link>
167
+ {/* @endif */}
168
+ {/* @if react-hook-form */}
169
+ <Link href="/form" underline="hover">
170
+ Form
171
+ </Link>
172
+ {/* @endif */}
173
+ <Button size="sm" variant="outlined" onClick={() => setScheme(otherScheme)}>
174
+ {otherScheme}
175
+ </Button>
176
+ </Flex>
177
+ </Flex>
178
+ <View as="main" px={3} py={4}>
179
+ {children}
180
+ </View>
181
+ </Providers>
182
+ )
183
+ // @endif
184
+ }
@@ -0,0 +1,14 @@
1
+ import type { Config } from 'vike/types'
2
+
3
+ // The settings of every page: https://vike.dev/config
4
+ export default {
5
+ // Isomorphic: every page is HTML at build time, then the app moves between pages in the
6
+ // browser, with no reload.
7
+ prerender: true,
8
+ clientRouting: true,
9
+ hydrationCanBeAborted: true,
10
+ // +Layout is a setting of this app's own: the component every page renders inside.
11
+ meta: {
12
+ Layout: { env: { server: true, client: true } },
13
+ },
14
+ } satisfies Config
@@ -0,0 +1,41 @@
1
+ // @if !ssg
2
+ import { createRoot, hydrateRoot, type Root } from 'react-dom/client'
3
+ // @if msw
4
+ import type { OnRenderClientAsync } from 'vike/types'
5
+ import { startMocks } from '../mocks/start'
6
+ // @else
7
+ import type { OnRenderClientSync } from 'vike/types'
8
+ // @endif
9
+ import { PageShell } from './PageShell'
10
+
11
+ let root: Root | undefined
12
+ // @if msw
13
+ const mocks = startMocks()
14
+ // @endif
15
+
16
+ /** Takes over the page the server drew, then draws each page the app moves to. */
17
+ // @if msw
18
+ export const onRenderClient: OnRenderClientAsync = async (pageContext) => {
19
+ await mocks
20
+ const page = <PageShell pageContext={pageContext} />
21
+ const container = document.getElementById('root')!
22
+ if (pageContext.isHydration) {
23
+ root = hydrateRoot(container, page)
24
+ } else {
25
+ root ??= createRoot(container)
26
+ root.render(page)
27
+ }
28
+ }
29
+ // @else
30
+ export const onRenderClient: OnRenderClientSync = (pageContext) => {
31
+ const page = <PageShell pageContext={pageContext} />
32
+ const container = document.getElementById('root')!
33
+ if (pageContext.isHydration) {
34
+ root = hydrateRoot(container, page)
35
+ } else {
36
+ root ??= createRoot(container)
37
+ root.render(page)
38
+ }
39
+ }
40
+ // @endif
41
+ // @endif
@@ -0,0 +1,28 @@
1
+ import createEmotionServer from '@emotion/server/create-instance'
2
+ import { renderToString } from 'react-dom/server'
3
+ import { styleCache } from '@soroush.tech/design-system/engine'
4
+ import { dangerouslySkipEscape, escapeInject } from 'vike/server'
5
+ import type { OnRenderHtmlSync } from 'vike/types'
6
+ import { PageShell } from './PageShell'
7
+
8
+ /**
9
+ * Renders the page to HTML - at build time, as the app is prerendered - with the styles it uses
10
+ * in the head, so it is drawn styled before any script runs.
11
+ */
12
+ export const onRenderHtml: OnRenderHtmlSync = (pageContext) => {
13
+ const { extractCriticalToChunks, constructStyleTagsFromChunks } = createEmotionServer(styleCache)
14
+ const html = renderToString(<PageShell pageContext={pageContext} />)
15
+ const styles = constructStyleTagsFromChunks(extractCriticalToChunks(html))
16
+ return escapeInject`<!doctype html>
17
+ <html lang="en">
18
+ <head>
19
+ <meta charset="UTF-8" />
20
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
21
+ <title>__TITLE__</title>
22
+ ${dangerouslySkipEscape(styles)}
23
+ </head>
24
+ <body>
25
+ <div id="root">${dangerouslySkipEscape(html)}</div>
26
+ </body>
27
+ </html>`
28
+ }
@@ -0,0 +1,48 @@
1
+ import { StrictMode } from 'react'
2
+ import { CacheProvider, styleCache } from '@soroush.tech/design-system/engine'
3
+ // @if redux-toolkit
4
+ import { Provider as StoreProvider } from 'react-redux'
5
+ // @endif
6
+ import type { PageContext } from 'vike/types'
7
+ // @if redux-toolkit
8
+ import { store } from '../state/store'
9
+ // @endif
10
+ import { PageContextProvider } from './usePageContext'
11
+
12
+ /**
13
+ * The page inside its +Layout. The Emotion cache is the design system's, so the styles the page
14
+ * uses are found where it is drawn, and every component of the page can read its pageContext.
15
+ */
16
+ export function PageShell({ pageContext }: { readonly pageContext: PageContext }) {
17
+ const { Page, config } = pageContext
18
+ const { Layout } = config
19
+ return (
20
+ <StrictMode>
21
+ <CacheProvider value={styleCache}>
22
+ {/* @if redux-toolkit */}
23
+ <StoreProvider store={store}>
24
+ <PageContextProvider pageContext={pageContext}>
25
+ {Layout ? (
26
+ <Layout>
27
+ <Page />
28
+ </Layout>
29
+ ) : (
30
+ <Page />
31
+ )}
32
+ </PageContextProvider>
33
+ </StoreProvider>
34
+ {/* @else */}
35
+ <PageContextProvider pageContext={pageContext}>
36
+ {Layout ? (
37
+ <Layout>
38
+ <Page />
39
+ </Layout>
40
+ ) : (
41
+ <Page />
42
+ )}
43
+ </PageContextProvider>
44
+ {/* @endif */}
45
+ </CacheProvider>
46
+ </StrictMode>
47
+ )
48
+ }
@@ -0,0 +1,14 @@
1
+ import { Flex } from '@soroush.tech/design-system/Flex'
2
+ import { Link } from '@soroush.tech/design-system/Link'
3
+ import { Typography } from '@soroush.tech/design-system/Typography'
4
+
5
+ /** Shown for a page that does not exist, and when a page fails to render. */
6
+ export default function Page() {
7
+ return (
8
+ <Flex gap={2} alignItems="flex-start">
9
+ <Typography variant="h2">Page not found</Typography>
10
+ <Typography color="secondary">This page does not exist, or it could not be shown.</Typography>
11
+ <Link href="/">Back home</Link>
12
+ </Flex>
13
+ )
14
+ }
@@ -0,0 +1,14 @@
1
+ import { Flex } from '@soroush.tech/design-system/Flex'
2
+ import { Typography } from '@soroush.tech/design-system/Typography'
3
+
4
+ export default function Page() {
5
+ return (
6
+ <Flex gap={2}>
7
+ <Typography variant="h2">About</Typography>
8
+ <Typography color="secondary">
9
+ A second page: it is HTML with its styles from the build, and the app moves to it without a
10
+ reload.
11
+ </Typography>
12
+ </Flex>
13
+ )
14
+ }
@@ -0,0 +1,33 @@
1
+ import { Button } from '@soroush.tech/design-system/Button'
2
+ import { Flex } from '@soroush.tech/design-system/Flex'
3
+ import { Typography } from '@soroush.tech/design-system/Typography'
4
+ // @if !ssg
5
+ import { Counter } from './Counter'
6
+ // @endif
7
+ // @if tanstack-query || swr || msw
8
+ import { Greeting } from './Greeting'
9
+ // @endif
10
+
11
+ export default function Page() {
12
+ return (
13
+ <Flex gap={2} alignItems="flex-start">
14
+ <Typography variant="h2">__TITLE__</Typography>
15
+ <Typography color="secondary">
16
+ A Vike app on the design system. Edit src/pages/index/+Page.tsx, and make the themes your
17
+ own in src/theme/themes.ts.
18
+ </Typography>
19
+ {/* @if tanstack-query || swr || msw */}
20
+ <Greeting />
21
+ {/* @endif */}
22
+ {/* @if !ssg */}
23
+ <Counter />
24
+ {/* @endif */}
25
+ <Flex flexDirection="row" gap={1}>
26
+ <Button href="https://docs.soroush.tech">Components</Button>
27
+ <Button href="https://vike.dev" variant="outlined">
28
+ Vike
29
+ </Button>
30
+ </Flex>
31
+ </Flex>
32
+ )
33
+ }
@@ -0,0 +1,20 @@
1
+ // @if !ssg
2
+ import { useState } from 'react'
3
+ import { Button } from '@soroush.tech/design-system/Button'
4
+ import { Flex } from '@soroush.tech/design-system/Flex'
5
+ import { Typography } from '@soroush.tech/design-system/Typography'
6
+
7
+ /** A count, held in the component's own state, and the button that adds to it. */
8
+ export function Counter() {
9
+ const [count, setCount] = useState(0)
10
+ const increment = () => setCount(count + 1)
11
+ return (
12
+ <Flex flexDirection="row" alignItems="center" gap={2}>
13
+ <Button size="sm" variant="outlined" onClick={increment}>
14
+ Count
15
+ </Button>
16
+ <Typography>Count: {count}</Typography>
17
+ </Flex>
18
+ )
19
+ }
20
+ // @endif
@@ -0,0 +1,49 @@
1
+ // @if tanstack-query || swr || msw
2
+ // @if tanstack-query
3
+ import { useQuery } from '@tanstack/react-query'
4
+ // @elif swr
5
+ import useSWR from 'swr'
6
+ // @else
7
+ import { useEffect, useState } from 'react'
8
+ // @endif
9
+ import { Typography } from '@soroush.tech/design-system/Typography'
10
+ // @if !tanstack-query && !swr
11
+ import type { Greeting as Reply } from '../../data/api'
12
+ // @endif
13
+ import { fetchGreeting } from '../../data/api'
14
+
15
+ // @if tanstack-query
16
+ /** What the API says, read with a query of TanStack Query. */
17
+ export function Greeting() {
18
+ const { data } = useQuery({ queryKey: ['greeting'], queryFn: fetchGreeting })
19
+ return (
20
+ <Typography color="secondary">
21
+ {data ? data.message : 'Asking the API for a greeting...'}
22
+ </Typography>
23
+ )
24
+ }
25
+ // @elif swr
26
+ /** What the API says, read with SWR. */
27
+ export function Greeting() {
28
+ const { data } = useSWR('greeting', fetchGreeting)
29
+ return (
30
+ <Typography color="secondary">
31
+ {data ? data.message : 'Asking the API for a greeting...'}
32
+ </Typography>
33
+ )
34
+ }
35
+ // @else
36
+ /** What the API says, read with fetch, as the page loads. */
37
+ export function Greeting() {
38
+ const [data, setData] = useState<Reply>()
39
+ useEffect(() => {
40
+ fetchGreeting().then(setData, () => setData({ message: 'The API did not answer.' }))
41
+ }, [])
42
+ return (
43
+ <Typography color="secondary">
44
+ {data ? data.message : 'Asking the API for a greeting...'}
45
+ </Typography>
46
+ )
47
+ }
48
+ // @endif
49
+ // @endif