serve-my-md 1.1.0

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 (49) hide show
  1. package/README.md +52 -0
  2. package/bin/index.js +487 -0
  3. package/index.html +70 -0
  4. package/package.json +111 -0
  5. package/shared/constants.json +3 -0
  6. package/shared/index.d.ts +34 -0
  7. package/web/.cta.json +12 -0
  8. package/web/.cursorrules +7 -0
  9. package/web/.prettierignore +3 -0
  10. package/web/.vscode/settings.json +11 -0
  11. package/web/README.md +489 -0
  12. package/web/components.json +21 -0
  13. package/web/eslint.config.js +5 -0
  14. package/web/index.html +66 -0
  15. package/web/prettier.config.js +10 -0
  16. package/web/public/og-image.png +0 -0
  17. package/web/src/.generated/output.json +1 -0
  18. package/web/src/.generated/paths.json +1 -0
  19. package/web/src/App.tsx +15 -0
  20. package/web/src/article.css +199 -0
  21. package/web/src/components/Bettercrumb.tsx +86 -0
  22. package/web/src/components/Fonts.tsx +13 -0
  23. package/web/src/components/Header.tsx +10 -0
  24. package/web/src/components/IntentLink.tsx +20 -0
  25. package/web/src/components/Rendrer.tsx +140 -0
  26. package/web/src/components/Search.tsx +275 -0
  27. package/web/src/components/Sidebar.tsx +89 -0
  28. package/web/src/components/ThemeSwitcher.tsx +46 -0
  29. package/web/src/components/ui/breadcrumb.tsx +122 -0
  30. package/web/src/components/ui/button.tsx +60 -0
  31. package/web/src/components/ui/collapsible.tsx +33 -0
  32. package/web/src/components/ui/dropdown-menu.tsx +255 -0
  33. package/web/src/components/ui/input.tsx +21 -0
  34. package/web/src/components/ui/kbd.tsx +28 -0
  35. package/web/src/components/ui/separator.tsx +26 -0
  36. package/web/src/components/ui/sheet.tsx +139 -0
  37. package/web/src/components/ui/sidebar.tsx +727 -0
  38. package/web/src/components/ui/skeleton.tsx +13 -0
  39. package/web/src/components/ui/tooltip.tsx +59 -0
  40. package/web/src/contexts.ts +10 -0
  41. package/web/src/hooks/useMobile.ts +19 -0
  42. package/web/src/lib/utils.tsx +89 -0
  43. package/web/src/main.tsx +100 -0
  44. package/web/src/reportWebVitals.ts +13 -0
  45. package/web/src/styles.css +196 -0
  46. package/web/src/types/index.ts +3 -0
  47. package/web/tsconfig.json +35 -0
  48. package/web/vite.config.ts +31 -0
  49. package/web/vitest.config.ts +16 -0
package/package.json ADDED
@@ -0,0 +1,111 @@
1
+ {
2
+ "name": "serve-my-md",
3
+ "version": "1.1.0",
4
+ "type": "module",
5
+ "description": "Generate beautiful SEO-friendly static websites from Markdown files.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/AshishAntil07/serve-my-md.git"
9
+ },
10
+ "homepage": "https://ashishantil.dev/serve-my-md",
11
+ "author": "AshishAntil07 <ashishantil.antil07@gmail.com>",
12
+ "license": "MIT",
13
+ "keywords": [
14
+ "markdown",
15
+ "docs",
16
+ "documentation",
17
+ "ssg",
18
+ "documentation-generator",
19
+ "seo",
20
+ "vite",
21
+ "react"
22
+ ],
23
+ "bin": {
24
+ "serve-my-md": "bin/index.js"
25
+ },
26
+ "publishConfig": {
27
+ "access": "public"
28
+ },
29
+ "files": [
30
+ "bin",
31
+ "web",
32
+ "shared",
33
+ "index.html",
34
+ "README.md",
35
+ "LICENSE",
36
+ "package.json"
37
+ ],
38
+ "scripts": {
39
+ "dev": "tsup cli/src/index.ts --tsconfig cli/tsconfig.json --watch",
40
+ "build": "tsup cli/src/index.ts --tsconfig cli/tsconfig.json",
41
+ "start": "node bin/index.js",
42
+ "test": "vitest run --config cli/vitest.config.ts",
43
+ "dev:web": "vite --config web/vite.config.ts --port 3000",
44
+ "build:web": "vite build --config web/vite.config.ts",
45
+ "serve:web": "vite preview --config web/vite.config.ts",
46
+ "test:web": "vitest run --config web/vitest.config.ts",
47
+ "lint:web": "eslint web",
48
+ "format:web": "prettier --write web",
49
+ "check:web": "prettier --write web && eslint web --fix",
50
+ "prepublishOnly": "pnpm build"
51
+ },
52
+ "devDependencies": {
53
+ "@tanstack/devtools-vite": "^0.3.11",
54
+ "@tanstack/eslint-config": "^0.3.0",
55
+ "@testing-library/dom": "^10.4.0",
56
+ "@testing-library/react": "^16.2.0",
57
+ "@types/markdown-it": "^14",
58
+ "@types/markdown-it-footnote": "^3.0.4",
59
+ "@types/node": "^24.10.1",
60
+ "@types/prismjs": "^1.26.5",
61
+ "@types/react": "^19.2.0",
62
+ "@types/react-dom": "^19.2.0",
63
+ "@vitejs/plugin-react": "^5.0.4",
64
+ "babel-plugin-react-compiler": "^1.0.0",
65
+ "esbuild": "^0.27.3",
66
+ "jsdom": "^27.0.0",
67
+ "prettier": "^3.6.2",
68
+ "tsup": "^8.5.1",
69
+ "typescript": "^5.9.3",
70
+ "vite": "^7.1.7",
71
+ "vite-tsconfig-paths": "^6.1.1",
72
+ "vitest": "^4.0.15",
73
+ "web-vitals": "^5.1.0"
74
+ },
75
+ "dependencies": {
76
+ "@inquirer/prompts": "^7.10.1",
77
+ "@radix-ui/react-collapsible": "^1.1.12",
78
+ "@radix-ui/react-dialog": "^1.1.15",
79
+ "@radix-ui/react-dropdown-menu": "^2.1.16",
80
+ "@radix-ui/react-separator": "^1.1.8",
81
+ "@radix-ui/react-slot": "^1.2.4",
82
+ "@radix-ui/react-tooltip": "^1.2.8",
83
+ "@tailwindcss/vite": "^4.0.6",
84
+ "@tanstack/react-devtools": "^0.7.0",
85
+ "@tanstack/react-router": "^1.132.0",
86
+ "@tanstack/react-router-devtools": "^1.132.0",
87
+ "@types/path-browserify": "^1.0.3",
88
+ "class-variance-authority": "^0.7.1",
89
+ "clsx": "^2.1.1",
90
+ "commander": "^14.0.3",
91
+ "lucide-react": "^0.544.0",
92
+ "markdown-it": "^14.1.1",
93
+ "markdown-it-footnote": "^4.0.0",
94
+ "markdown-it-github-headings": "^2.0.1",
95
+ "markdown-it-prism": "^3.0.1",
96
+ "markdown-it-task-lists": "^2.1.1",
97
+ "minimatch": "^10.2.0",
98
+ "path-browserify": "^1.0.1",
99
+ "prismjs": "^1.30.0",
100
+ "react": "^19.2.0",
101
+ "react-dom": "^19.2.0",
102
+ "react-hotkeys-hook": "^5.2.1",
103
+ "tailwind-merge": "^3.0.2",
104
+ "tailwindcss": "^4.0.6",
105
+ "tw-animate-css": "^1.3.6"
106
+ },
107
+ "volta": {
108
+ "node": "26.1.0",
109
+ "npm": "11.15.0"
110
+ }
111
+ }
@@ -0,0 +1,3 @@
1
+ {
2
+ "STATIC_TEMP_CONTENT_PREFIX": "__smm_static_temp_content__"
3
+ }
@@ -0,0 +1,34 @@
1
+ export interface Out {
2
+ rootTitle: string;
3
+ description: string;
4
+ baseRoute: string;
5
+ defaultTheme: string;
6
+ favicon?: string;
7
+ logo?: string;
8
+ name: string;
9
+ version?: string;
10
+ fonts?: {
11
+ title: string;
12
+ body: string;
13
+ mono: string;
14
+ };
15
+ showNameWithLogo: boolean;
16
+ outDir: string;
17
+ routes: Route[];
18
+ }
19
+ export interface Route {
20
+ path: string;
21
+ content: string;
22
+ }
23
+
24
+ export type RouteTree = {
25
+ label: string;
26
+ children: RouteTree[] | null;
27
+ pathSegment: string;
28
+ isGrouper?: boolean;
29
+ };
30
+
31
+ /**
32
+ * A unique prefix for static content in the HTML template, used to replace temp content with react components.
33
+ */
34
+ export const STATIC_TEMP_CONTENT_PREFIX = "__smm_static_temp_content__";
package/web/.cta.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "projectName": "web",
3
+ "mode": "code-router",
4
+ "typescript": true,
5
+ "tailwind": true,
6
+ "packageManager": "npm",
7
+ "addOnOptions": {},
8
+ "git": true,
9
+ "version": 1,
10
+ "framework": "react-cra",
11
+ "chosenAddOns": ["eslint", "compiler", "shadcn"]
12
+ }
@@ -0,0 +1,7 @@
1
+ # shadcn instructions
2
+
3
+ Use the latest version of Shadcn to install new components, like this command to add a button component:
4
+
5
+ ```bash
6
+ pnpx shadcn@latest add button
7
+ ```
@@ -0,0 +1,3 @@
1
+ package-lock.json
2
+ pnpm-lock.yaml
3
+ yarn.lock
@@ -0,0 +1,11 @@
1
+ {
2
+ "files.watcherExclude": {
3
+ "**/routeTree.gen.ts": true
4
+ },
5
+ "search.exclude": {
6
+ "**/routeTree.gen.ts": true
7
+ },
8
+ "files.readonlyInclude": {
9
+ "**/routeTree.gen.ts": true
10
+ }
11
+ }
package/web/README.md ADDED
@@ -0,0 +1,489 @@
1
+ Welcome to your new TanStack app!
2
+
3
+ # Getting Started
4
+
5
+ To run this application:
6
+
7
+ ```bash
8
+ npm install
9
+ npm run start
10
+ ```
11
+
12
+ # Building For Production
13
+
14
+ To build this application for production:
15
+
16
+ ```bash
17
+ npm run build
18
+ ```
19
+
20
+ ## Testing
21
+
22
+ This project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:
23
+
24
+ ```bash
25
+ npm run test
26
+ ```
27
+
28
+ ## Styling
29
+
30
+ This project uses [Tailwind CSS](https://tailwindcss.com/) for styling.
31
+
32
+ ## Linting & Formatting
33
+
34
+ This project uses [eslint](https://eslint.org/) and [prettier](https://prettier.io/) for linting and formatting. Eslint is configured using [tanstack/eslint-config](https://tanstack.com/config/latest/docs/eslint). The following scripts are available:
35
+
36
+ ```bash
37
+ npm run lint
38
+ npm run format
39
+ npm run check
40
+ ```
41
+
42
+ ## Shadcn
43
+
44
+ Add components using the latest version of [Shadcn](https://ui.shadcn.com/).
45
+
46
+ ```bash
47
+ pnpx shadcn@latest add button
48
+ ```
49
+
50
+ ## Routing
51
+
52
+ This project uses [TanStack Router](https://tanstack.com/router). The initial setup is a code based router. Which means that the routes are defined in code (in the `./src/main.tsx` file). If you like you can also use a file based routing setup by following the [File Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/file-based-routing) guide.
53
+
54
+ ### Adding A Route
55
+
56
+ To add a new route to your application just add another `createRoute` call to the `./src/main.tsx` file. The example below adds a new `/about`route to the root route.
57
+
58
+ ```tsx
59
+ const aboutRoute = createRoute({
60
+ getParentRoute: () => rootRoute,
61
+ path: '/about',
62
+ component: () => <h1>About</h1>,
63
+ })
64
+ ```
65
+
66
+ You will also need to add the route to the `routeTree` in the `./src/main.tsx` file.
67
+
68
+ ```tsx
69
+ const routeTree = rootRoute.addChildren([indexRoute, aboutRoute])
70
+ ```
71
+
72
+ With this set up you should be able to navigate to `/about` and see the about page.
73
+
74
+ Of course you don't need to implement the About page in the `main.tsx` file. You can create that component in another file and import it into the `main.tsx` file, then use it in the `component` property of the `createRoute` call, like so:
75
+
76
+ ```tsx
77
+ import About from './components/About.tsx'
78
+
79
+ const aboutRoute = createRoute({
80
+ getParentRoute: () => rootRoute,
81
+ path: '/about',
82
+ component: About,
83
+ })
84
+ ```
85
+
86
+ That is how we have the `App` component set up with the home page.
87
+
88
+ For more information on the options you have when you are creating code based routes check out the [Code Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/code-based-routing) documentation.
89
+
90
+ Now that you have two routes you can use a `Link` component to navigate between them.
91
+
92
+ ### Adding Links
93
+
94
+ To use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.
95
+
96
+ ```tsx
97
+ import { Link } from '@tanstack/react-router'
98
+ ```
99
+
100
+ Then anywhere in your JSX you can use it like so:
101
+
102
+ ```tsx
103
+ <Link to="/about">About</Link>
104
+ ```
105
+
106
+ This will create a link that will navigate to the `/about` route.
107
+
108
+ More information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).
109
+
110
+ ### Using A Layout
111
+
112
+ Layouts can be used to wrap the contents of the routes in menus, headers, footers, etc.
113
+
114
+ There is already a layout in the `src/main.tsx` file:
115
+
116
+ ```tsx
117
+ const rootRoute = createRootRoute({
118
+ component: () => (
119
+ <>
120
+ <Outlet />
121
+ <TanStackRouterDevtools />
122
+ </>
123
+ ),
124
+ })
125
+ ```
126
+
127
+ You can use the React component specified in the `component` property of the `rootRoute` to wrap the contents of the routes. The `<Outlet />` component is used to render the current route within the body of the layout. For example you could add a header to the layout like so:
128
+
129
+ ```tsx
130
+ import { Link } from '@tanstack/react-router'
131
+
132
+ const rootRoute = createRootRoute({
133
+ component: () => (
134
+ <>
135
+ <header>
136
+ <nav>
137
+ <Link to="/">Home</Link>
138
+ <Link to="/about">About</Link>
139
+ </nav>
140
+ </header>
141
+ <Outlet />
142
+ <TanStackRouterDevtools />
143
+ </>
144
+ ),
145
+ })
146
+ ```
147
+
148
+ The `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.
149
+
150
+ More information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).
151
+
152
+ ### Migrating To File Base Routing
153
+
154
+ First you need to add the Vite plugin for Tanstack Router:
155
+
156
+ ```bash
157
+ npm install @tanstack/router-plugin -D
158
+ ```
159
+
160
+ From there you need to update your `vite.config.js` file to use the plugin:
161
+
162
+ ```ts
163
+ import { defineConfig } from 'vite'
164
+ import viteReact from '@vitejs/plugin-react'
165
+ import { TanStackRouterVite } from '@tanstack/router-plugin/vite'
166
+ import tailwindcss from '@tailwindcss/vite'
167
+
168
+ // https://vitejs.dev/config/
169
+ export default defineConfig({
170
+ plugins: [TanStackRouterVite(), viteReact(), tailwindcss()],
171
+ })
172
+ ```
173
+
174
+ Now you'll need to rearrange your files a little bit. That starts with creating a `routes` directory in the `src` directory:
175
+
176
+ ```bash
177
+ mkdir src/routes
178
+ ```
179
+
180
+ Then you'll need to create a `src/routes/__root.tsx` file with the contents of the root route that was in `main.tsx`.
181
+
182
+ ```tsx
183
+ import { Outlet, createRootRoute } from '@tanstack/react-router'
184
+ import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'
185
+
186
+ export const Route = createRootRoute({
187
+ component: () => (
188
+ <>
189
+ <Outlet />
190
+ <TanStackRouterDevtools />
191
+ </>
192
+ ),
193
+ })
194
+ ```
195
+
196
+ Next up you'll need to move your home route code into `src/routes/index.tsx`
197
+
198
+ ```tsx
199
+ import { createFileRoute } from '@tanstack/react-router'
200
+
201
+ import logo from '../logo.svg'
202
+ import '../App.css'
203
+
204
+ export const Route = createFileRoute('/')({
205
+ component: App,
206
+ })
207
+
208
+ function App() {
209
+ return (
210
+ <div className="text-center">
211
+ <header className="min-h-screen flex flex-col items-center justify-center bg-[#282c34] text-white text-[calc(10px+2vmin)]">
212
+ <img
213
+ src={logo}
214
+ className="h-[40vmin] pointer-events-none animate-[spin_20s_linear_infinite]"
215
+ alt="logo"
216
+ />
217
+ <p>
218
+ Edit <code>src/App.tsx</code> and save to reload.
219
+ </p>
220
+ <a
221
+ className="text-[#61dafb] hover:underline"
222
+ href="https://reactjs.org"
223
+ target="_blank"
224
+ rel="noopener noreferrer"
225
+ >
226
+ Learn React
227
+ </a>
228
+ <a
229
+ className="text-[#61dafb] hover:underline"
230
+ href="https://tanstack.com"
231
+ target="_blank"
232
+ rel="noopener noreferrer"
233
+ >
234
+ Learn TanStack
235
+ </a>
236
+ </header>
237
+ </div>
238
+ )
239
+ }
240
+ ```
241
+
242
+ At this point you can delete `src/App.tsx`, you will no longer need it as the contents have moved into `src/routes/index.tsx`.
243
+
244
+ The only additional code is the `createFileRoute` function that tells TanStack Router where to render the route. Helpfully the Vite plugin will keep the path argument that goes to `createFileRoute` automatically in sync with the file system.
245
+
246
+ Finally the `src/main.tsx` file can be simplified down to this:
247
+
248
+ ```tsx
249
+ import { StrictMode } from 'react'
250
+ import ReactDOM from 'react-dom/client'
251
+ import { RouterProvider, createRouter } from '@tanstack/react-router'
252
+
253
+ // Import the generated route tree
254
+ import { routeTree } from './routeTree.gen'
255
+
256
+ import './styles.css'
257
+ import reportWebVitals from './reportWebVitals.ts'
258
+
259
+ // Create a new router instance
260
+ const router = createRouter({
261
+ routeTree,
262
+ defaultPreload: 'intent',
263
+ defaultPreloadStaleTime: 0,
264
+ scrollRestoration: true,
265
+ defaultStructuralSharing: true,
266
+ })
267
+
268
+ // Register the router instance for type safety
269
+ declare module '@tanstack/react-router' {
270
+ interface Register {
271
+ router: typeof router
272
+ }
273
+ }
274
+
275
+ // Render the app
276
+ const rootElement = document.getElementById('app')!
277
+ if (!rootElement.innerHTML) {
278
+ const root = ReactDOM.createRoot(rootElement)
279
+ root.render(
280
+ <StrictMode>
281
+ <RouterProvider router={router} />
282
+ </StrictMode>,
283
+ )
284
+ }
285
+
286
+ // If you want to start measuring performance in your app, pass a function
287
+ // to log results (for example: reportWebVitals(console.log))
288
+ // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
289
+ reportWebVitals()
290
+ ```
291
+
292
+ Now you've got a file based routing setup in your project! Let's have some fun with it! Just create a file in `about.tsx` in `src/routes` and it if the application is running TanStack will automatically add contents to the file and you'll have the start of your `/about` route ready to go with no additional work. You can see why folks find File Based Routing so easy to use.
293
+
294
+ You can find out everything you need to know on how to use file based routing in the [File Based Routing](https://tanstack.com/router/latest/docs/framework/react/guide/file-based-routing) documentation.
295
+
296
+ ## Data Fetching
297
+
298
+ There are multiple ways to fetch data in your application. You can use TanStack Query to fetch data from a server. But you can also use the `loader` functionality built into TanStack Router to load the data for a route before it's rendered.
299
+
300
+ For example:
301
+
302
+ ```tsx
303
+ const peopleRoute = createRoute({
304
+ getParentRoute: () => rootRoute,
305
+ path: '/people',
306
+ loader: async () => {
307
+ const response = await fetch('https://swapi.dev/api/people')
308
+ return response.json() as Promise<{
309
+ results: {
310
+ name: string
311
+ }[]
312
+ }>
313
+ },
314
+ component: () => {
315
+ const data = peopleRoute.useLoaderData()
316
+ return (
317
+ <ul>
318
+ {data.results.map((person) => (
319
+ <li key={person.name}>{person.name}</li>
320
+ ))}
321
+ </ul>
322
+ )
323
+ },
324
+ })
325
+ ```
326
+
327
+ Loaders simplify your data fetching logic dramatically. Check out more information in the [Loader documentation](https://tanstack.com/router/latest/docs/framework/react/guide/data-loading#loader-parameters).
328
+
329
+ ### React-Query
330
+
331
+ React-Query is an excellent addition or alternative to route loading and integrating it into you application is a breeze.
332
+
333
+ First add your dependencies:
334
+
335
+ ```bash
336
+ npm install @tanstack/react-query @tanstack/react-query-devtools
337
+ ```
338
+
339
+ Next we'll need to create a query client and provider. We recommend putting those in `main.tsx`.
340
+
341
+ ```tsx
342
+ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
343
+
344
+ // ...
345
+
346
+ const queryClient = new QueryClient()
347
+
348
+ // ...
349
+
350
+ if (!rootElement.innerHTML) {
351
+ const root = ReactDOM.createRoot(rootElement)
352
+
353
+ root.render(
354
+ <QueryClientProvider client={queryClient}>
355
+ <RouterProvider router={router} />
356
+ </QueryClientProvider>,
357
+ )
358
+ }
359
+ ```
360
+
361
+ You can also add TanStack Query Devtools to the root route (optional).
362
+
363
+ ```tsx
364
+ import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
365
+
366
+ const rootRoute = createRootRoute({
367
+ component: () => (
368
+ <>
369
+ <Outlet />
370
+ <ReactQueryDevtools buttonPosition="top-right" />
371
+ <TanStackRouterDevtools />
372
+ </>
373
+ ),
374
+ })
375
+ ```
376
+
377
+ Now you can use `useQuery` to fetch your data.
378
+
379
+ ```tsx
380
+ import { useQuery } from '@tanstack/react-query'
381
+
382
+ import './App.css'
383
+
384
+ function App() {
385
+ const { data } = useQuery({
386
+ queryKey: ['people'],
387
+ queryFn: () =>
388
+ fetch('https://swapi.dev/api/people')
389
+ .then((res) => res.json())
390
+ .then((data) => data.results as { name: string }[]),
391
+ initialData: [],
392
+ })
393
+
394
+ return (
395
+ <div>
396
+ <ul>
397
+ {data.map((person) => (
398
+ <li key={person.name}>{person.name}</li>
399
+ ))}
400
+ </ul>
401
+ </div>
402
+ )
403
+ }
404
+
405
+ export default App
406
+ ```
407
+
408
+ You can find out everything you need to know on how to use React-Query in the [React-Query documentation](https://tanstack.com/query/latest/docs/framework/react/overview).
409
+
410
+ ## State Management
411
+
412
+ Another common requirement for React applications is state management. There are many options for state management in React. TanStack Store provides a great starting point for your project.
413
+
414
+ First you need to add TanStack Store as a dependency:
415
+
416
+ ```bash
417
+ npm install @tanstack/store
418
+ ```
419
+
420
+ Now let's create a simple counter in the `src/App.tsx` file as a demonstration.
421
+
422
+ ```tsx
423
+ import { useStore } from '@tanstack/react-store'
424
+ import { Store } from '@tanstack/store'
425
+ import './App.css'
426
+
427
+ const countStore = new Store(0)
428
+
429
+ function App() {
430
+ const count = useStore(countStore)
431
+ return (
432
+ <div>
433
+ <button onClick={() => countStore.setState((n) => n + 1)}>
434
+ Increment - {count}
435
+ </button>
436
+ </div>
437
+ )
438
+ }
439
+
440
+ export default App
441
+ ```
442
+
443
+ One of the many nice features of TanStack Store is the ability to derive state from other state. That derived state will update when the base state updates.
444
+
445
+ Let's check this out by doubling the count using derived state.
446
+
447
+ ```tsx
448
+ import { useStore } from '@tanstack/react-store'
449
+ import { Store, Derived } from '@tanstack/store'
450
+ import './App.css'
451
+
452
+ const countStore = new Store(0)
453
+
454
+ const doubledStore = new Derived({
455
+ fn: () => countStore.state * 2,
456
+ deps: [countStore],
457
+ })
458
+ doubledStore.mount()
459
+
460
+ function App() {
461
+ const count = useStore(countStore)
462
+ const doubledCount = useStore(doubledStore)
463
+
464
+ return (
465
+ <div>
466
+ <button onClick={() => countStore.setState((n) => n + 1)}>
467
+ Increment - {count}
468
+ </button>
469
+ <div>Doubled - {doubledCount}</div>
470
+ </div>
471
+ )
472
+ }
473
+
474
+ export default App
475
+ ```
476
+
477
+ We use the `Derived` class to create a new store that is derived from another store. The `Derived` class has a `mount` method that will start the derived store updating.
478
+
479
+ Once we've created the derived store we can use it in the `App` component just like we would any other store using the `useStore` hook.
480
+
481
+ You can find out everything you need to know on how to use TanStack Store in the [TanStack Store documentation](https://tanstack.com/store/latest).
482
+
483
+ # Demo files
484
+
485
+ Files prefixed with `demo` can be safely deleted. They are there to provide a starting point for you to play around with the features you've installed.
486
+
487
+ # Learn More
488
+
489
+ You can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).
@@ -0,0 +1,21 @@
1
+ {
2
+ "$schema": "https://ui.shadcn.com/schema.json",
3
+ "style": "new-york",
4
+ "rsc": false,
5
+ "tsx": true,
6
+ "tailwind": {
7
+ "config": "",
8
+ "css": "src/styles.css",
9
+ "baseColor": "zinc",
10
+ "cssVariables": true,
11
+ "prefix": ""
12
+ },
13
+ "aliases": {
14
+ "components": "@/components",
15
+ "utils": "@/lib/utils",
16
+ "ui": "@/components/ui",
17
+ "lib": "@/lib",
18
+ "hooks": "@/hooks"
19
+ },
20
+ "iconLibrary": "lucide"
21
+ }