@tanstack/cta-framework-react-cra 0.10.0-alpha.20
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.
- package/ADD-ON-AUTHORING.md +169 -0
- package/LICENSE +21 -0
- package/add-ons/clerk/README.md +3 -0
- package/add-ons/clerk/assets/_dot_env.local.append +2 -0
- package/add-ons/clerk/assets/src/integrations/clerk/header-user.tsx +19 -0
- package/add-ons/clerk/assets/src/integrations/clerk/provider.tsx +18 -0
- package/add-ons/clerk/assets/src/routes/demo.clerk.tsx +20 -0
- package/add-ons/clerk/info.json +28 -0
- package/add-ons/clerk/logo.svg +6 -0
- package/add-ons/clerk/package.json +5 -0
- package/add-ons/clerk/small-logo.svg +5 -0
- package/add-ons/convex/README.md +4 -0
- package/add-ons/convex/assets/_dot_cursorrules.append +93 -0
- package/add-ons/convex/assets/_dot_env.local.append +3 -0
- package/add-ons/convex/assets/convex/products.ts +8 -0
- package/add-ons/convex/assets/convex/schema.ts +10 -0
- package/add-ons/convex/assets/src/integrations/convex/provider.tsx +20 -0
- package/add-ons/convex/assets/src/routes/demo.convex.tsx +33 -0
- package/add-ons/convex/info.json +23 -0
- package/add-ons/convex/package.json +6 -0
- package/add-ons/convex/small-logo.svg +5 -0
- package/add-ons/form/assets/src/components/demo.FormComponents.tsx.ejs +300 -0
- package/add-ons/form/assets/src/hooks/demo.form-context.ts +4 -0
- package/add-ons/form/assets/src/hooks/demo.form.ts +22 -0
- package/add-ons/form/assets/src/routes/demo.form.address.tsx.ejs +213 -0
- package/add-ons/form/assets/src/routes/demo.form.simple.tsx.ejs +77 -0
- package/add-ons/form/info.json +31 -0
- package/add-ons/form/package.json +6 -0
- package/add-ons/form/small-logo.svg +1 -0
- package/add-ons/module-federation/assets/module-federation.config.js.ejs +31 -0
- package/add-ons/module-federation/assets/src/demo-mf-component.tsx +3 -0
- package/add-ons/module-federation/assets/src/demo-mf-self-contained.tsx +11 -0
- package/add-ons/module-federation/info.json +8 -0
- package/add-ons/module-federation/package.json +5 -0
- package/add-ons/netlify/README.md +11 -0
- package/add-ons/netlify/info.json +8 -0
- package/add-ons/netlify/small-logo.svg +1 -0
- package/add-ons/sentry/assets/_dot_cursorrules.append +22 -0
- package/add-ons/sentry/assets/_dot_env.local.append +11 -0
- package/add-ons/sentry/assets/src/app/global-middleware.ts +11 -0
- package/add-ons/sentry/assets/src/routes/demo.sentry.testing.tsx +489 -0
- package/add-ons/sentry/info.json +17 -0
- package/add-ons/sentry/package.json +5 -0
- package/add-ons/sentry/small-logo.svg +1 -0
- package/add-ons/shadcn/README.md +7 -0
- package/add-ons/shadcn/assets/_dot_cursorrules.append +7 -0
- package/add-ons/shadcn/assets/components.json +21 -0
- package/add-ons/shadcn/assets/src/lib/utils.ts +6 -0
- package/add-ons/shadcn/assets/src/styles.css +138 -0
- package/add-ons/shadcn/info.json +8 -0
- package/add-ons/shadcn/package.json +9 -0
- package/add-ons/shadcn/small-logo.svg +1 -0
- package/add-ons/start/assets/_dot_gitignore.append +2 -0
- package/add-ons/start/assets/app.config.ts.ejs +32 -0
- package/add-ons/start/assets/src/api.ts +6 -0
- package/add-ons/start/assets/src/client.tsx.ejs +33 -0
- package/add-ons/start/assets/src/router.tsx.ejs +48 -0
- package/add-ons/start/assets/src/routes/api.demo-names.ts +11 -0
- package/add-ons/start/assets/src/routes/demo.start.api-request.tsx.ejs +33 -0
- package/add-ons/start/assets/src/routes/demo.start.server-funcs.tsx +50 -0
- package/add-ons/start/assets/src/ssr.tsx.ejs +30 -0
- package/add-ons/start/info.json +31 -0
- package/add-ons/start/package.json +13 -0
- package/add-ons/start/small-logo.svg +1 -0
- package/add-ons/store/assets/src/lib/demo-store.ts +13 -0
- package/add-ons/store/assets/src/routes/demo.store.tsx.ejs +75 -0
- package/add-ons/store/info.json +16 -0
- package/add-ons/store/package.json +6 -0
- package/add-ons/store/small-logo.svg +1 -0
- package/add-ons/t3env/README.md +16 -0
- package/add-ons/t3env/assets/src/env.ts +39 -0
- package/add-ons/t3env/info.json +8 -0
- package/add-ons/t3env/package.json +6 -0
- package/add-ons/t3env/small-logo.svg +6 -0
- package/add-ons/tRPC/assets/src/integrations/trpc/init.ts +9 -0
- package/add-ons/tRPC/assets/src/integrations/trpc/react.ts +4 -0
- package/add-ons/tRPC/assets/src/integrations/trpc/router.ts +21 -0
- package/add-ons/tRPC/assets/src/routes/api.trpc.$.tsx +16 -0
- package/add-ons/tRPC/info.json +9 -0
- package/add-ons/tRPC/package.json +9 -0
- package/add-ons/tRPC/small-logo.svg +1 -0
- package/add-ons/table/assets/src/data/demo-table-data.ts +50 -0
- package/add-ons/table/assets/src/routes/demo.table.tsx.ejs +373 -0
- package/add-ons/table/info.json +16 -0
- package/add-ons/table/package.json +7 -0
- package/add-ons/table/small-logo.svg +1 -0
- package/add-ons/tanstack-query/assets/src/integrations/tanstack-query/layout.tsx +5 -0
- package/add-ons/tanstack-query/assets/src/integrations/tanstack-query/root-provider.tsx.ejs +70 -0
- package/add-ons/tanstack-query/assets/src/routes/demo.tanstack-query.tsx.ejs +53 -0
- package/add-ons/tanstack-query/info.json +28 -0
- package/add-ons/tanstack-query/package.json +6 -0
- package/add-ons/tanstack-query/small-logo.svg +1 -0
- package/dist/index.js +18 -0
- package/dist/types/index.d.ts +1 -0
- package/examples/tanchat/README.md +37 -0
- package/examples/tanchat/assets/_dot_env.local.append +2 -0
- package/examples/tanchat/assets/public/example-guitar-flowers.jpg +0 -0
- package/examples/tanchat/assets/public/example-guitar-motherboard.jpg +0 -0
- package/examples/tanchat/assets/public/example-guitar-racing.jpg +0 -0
- package/examples/tanchat/assets/public/example-guitar-steamer-trunk.jpg +0 -0
- package/examples/tanchat/assets/public/example-guitar-superhero.jpg +0 -0
- package/examples/tanchat/assets/public/example-guitar-traveling.jpg +0 -0
- package/examples/tanchat/assets/public/example-guitar-video-games.jpg +0 -0
- package/examples/tanchat/assets/src/components/example-AIAssistant.tsx +173 -0
- package/examples/tanchat/assets/src/components/example-GuitarRecommendation.tsx +47 -0
- package/examples/tanchat/assets/src/data/example-guitars.ts +83 -0
- package/examples/tanchat/assets/src/demo.index.css +220 -0
- package/examples/tanchat/assets/src/integrations/tanchat/header-user.tsx +5 -0
- package/examples/tanchat/assets/src/routes/api.messages.ts +24 -0
- package/examples/tanchat/assets/src/routes/api.sse.ts +23 -0
- package/examples/tanchat/assets/src/routes/example.chat.tsx +159 -0
- package/examples/tanchat/assets/src/routes/example.guitars/$guitarId.tsx +50 -0
- package/examples/tanchat/assets/src/routes/example.guitars/index.tsx +54 -0
- package/examples/tanchat/assets/src/store/example-assistant.ts +3 -0
- package/examples/tanchat/assets/src/utils/demo.ai.ts +62 -0
- package/examples/tanchat/assets/src/utils/demo.sse.ts +31 -0
- package/examples/tanchat/assets/src/utils/demo.tools.ts +47 -0
- package/examples/tanchat/info.json +35 -0
- package/examples/tanchat/package.json +16 -0
- package/examples/tanchat/small-logo.svg +1 -0
- package/package.json +34 -0
- package/project/base/README.md.ejs +558 -0
- package/project/base/_dot_gitignore +5 -0
- package/project/base/_dot_vscode/settings.json.ejs +35 -0
- package/project/base/index.html.ejs +20 -0
- package/project/base/package.json +30 -0
- package/project/base/public/favicon.ico +0 -0
- package/project/base/public/logo192.png +0 -0
- package/project/base/public/logo512.png +0 -0
- package/project/base/public/manifest.json +25 -0
- package/project/base/public/robots.txt +3 -0
- package/project/base/src/App.css.ejs +38 -0
- package/project/base/src/App.test.tsx.ejs +10 -0
- package/project/base/src/App.tsx.ejs +63 -0
- package/project/base/src/components/Header.tsx.ejs +27 -0
- package/project/base/src/logo.svg +44 -0
- package/project/base/src/main.tsx.ejs +155 -0
- package/project/base/src/reportWebVitals.ts.ejs +28 -0
- package/project/base/src/routes/__root.tsx.ejs +82 -0
- package/project/base/src/routes/index.tsx.ejs +67 -0
- package/project/base/src/styles.css.ejs +15 -0
- package/project/base/tsconfig.json.ejs +29 -0
- package/project/base/vite.config.js.ejs +23 -0
- package/project/packages.json +20 -0
- package/src/index.ts +26 -0
- package/tests/react-cra.test.ts +150 -0
- package/tests/snapshots/react-cra/cr-js-form-npm.json +29 -0
- package/tests/snapshots/react-cra/cr-js-npm.json +23 -0
- package/tests/snapshots/react-cra/cr-ts-npm.json +24 -0
- package/tests/snapshots/react-cra/cr-ts-start-npm.json +28 -0
- package/tests/snapshots/react-cra/cr-ts-start-tanstack-query-npm.json +31 -0
- package/tests/snapshots/react-cra/fr-ts-biome-npm.json +26 -0
- package/tests/snapshots/react-cra/fr-ts-npm.json +24 -0
- package/tests/snapshots/react-cra/fr-ts-tw-npm.json +23 -0
- package/tests/test-utilities.ts +44 -0
- package/toolchains/biome/assets/biome.json +31 -0
- package/toolchains/biome/info.json +8 -0
- package/toolchains/biome/package.json +10 -0
- package/toolchains/biome/small-logo.svg +5 -0
- package/toolchains/eslint/assets/_dot_prettierignore +3 -0
- package/toolchains/eslint/assets/eslint.config.js +5 -0
- package/toolchains/eslint/assets/prettier.config.js +10 -0
- package/toolchains/eslint/info.json +8 -0
- package/toolchains/eslint/package.json +11 -0
- package/toolchains/eslint/small-logo.svg +7 -0
- package/tsconfig.json +17 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
<% if (tailwind) { %>@import "tailwindcss";
|
|
2
|
+
<% } %>
|
|
3
|
+
body {
|
|
4
|
+
<% if (tailwind) { %>@apply m-0;<% } else { %>margin: 0;<% } %>
|
|
5
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
|
|
6
|
+
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
|
|
7
|
+
sans-serif;
|
|
8
|
+
-webkit-font-smoothing: antialiased;
|
|
9
|
+
-moz-osx-font-smoothing: grayscale;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
code {
|
|
13
|
+
font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New",
|
|
14
|
+
monospace;
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<% if (!typescript) { ignoreFile() } %>{
|
|
2
|
+
<% if (addOnEnabled.eslint) { %>"include": ["**/*.ts", "**/*.tsx", "eslint.config.js", "prettier.config.js", "vite.config.js"],
|
|
3
|
+
<% } else { %>"include": ["**/*.ts", "**/*.tsx"],<% } %>
|
|
4
|
+
"compilerOptions": {
|
|
5
|
+
"target": "ES2022",
|
|
6
|
+
"jsx": "react-jsx",
|
|
7
|
+
"module": "ESNext",
|
|
8
|
+
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
9
|
+
"types": ["vite/client"],
|
|
10
|
+
|
|
11
|
+
/* Bundler mode */
|
|
12
|
+
"moduleResolution": "bundler",
|
|
13
|
+
"allowImportingTsExtensions": true,
|
|
14
|
+
"verbatimModuleSyntax": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"skipLibCheck": true,
|
|
19
|
+
"strict": true,
|
|
20
|
+
"noUnusedLocals": true,
|
|
21
|
+
"noUnusedParameters": true,
|
|
22
|
+
"noFallthroughCasesInSwitch": true,
|
|
23
|
+
"noUncheckedSideEffectImports": true,
|
|
24
|
+
"baseUrl": ".",
|
|
25
|
+
"paths": {
|
|
26
|
+
"@/*": ["./src/*"],
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
<% if (addOnEnabled.start) { ignoreFile() } %>import { defineConfig } from "vite";
|
|
2
|
+
import viteReact from "@vitejs/plugin-react";<% if (tailwind) { %>
|
|
3
|
+
import tailwindcss from "@tailwindcss/vite";
|
|
4
|
+
<% } %><%if (fileRouter) { %>
|
|
5
|
+
import { TanStackRouterVite } from "@tanstack/router-plugin/vite";<% } %><% if (addOnEnabled['module-federation']) { %>
|
|
6
|
+
import { federation } from "@module-federation/vite";<% } %>
|
|
7
|
+
import { resolve } from "node:path";<% if (addOnEnabled['module-federation']) { %>
|
|
8
|
+
import federationConfig from "./module-federation.config.js";
|
|
9
|
+
<% } %>
|
|
10
|
+
|
|
11
|
+
// https://vitejs.dev/config/
|
|
12
|
+
export default defineConfig({
|
|
13
|
+
plugins: [<% if(fileRouter) { %>TanStackRouterVite({ autoCodeSplitting: true }), <% } %>viteReact()<% if (tailwind) { %>, tailwindcss()<% } %><% if (addOnEnabled['module-federation']) { %>, federation(federationConfig)<% } %>],
|
|
14
|
+
test: {
|
|
15
|
+
globals: true,
|
|
16
|
+
environment: "jsdom",
|
|
17
|
+
},
|
|
18
|
+
resolve: {
|
|
19
|
+
alias: {
|
|
20
|
+
'@': resolve(__dirname, './src'),
|
|
21
|
+
},
|
|
22
|
+
}
|
|
23
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"typescript": {
|
|
3
|
+
"devDependencies": {
|
|
4
|
+
"@types/react": "^19.0.8",
|
|
5
|
+
"@types/react-dom": "^19.0.3",
|
|
6
|
+
"typescript": "^5.7.2"
|
|
7
|
+
}
|
|
8
|
+
},
|
|
9
|
+
"tailwindcss": {
|
|
10
|
+
"dependencies": {
|
|
11
|
+
"@tailwindcss/vite": "^4.0.6",
|
|
12
|
+
"tailwindcss": "^4.0.6"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"file-router": {
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@tanstack/router-plugin": "^1.114.3"
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path'
|
|
2
|
+
import { fileURLToPath } from 'node:url'
|
|
3
|
+
|
|
4
|
+
import { registerFramework } from '@tanstack/cta-engine'
|
|
5
|
+
|
|
6
|
+
export function register() {
|
|
7
|
+
registerFramework({
|
|
8
|
+
id: 'react-cra',
|
|
9
|
+
name: 'react',
|
|
10
|
+
description: 'Templates for React CRA',
|
|
11
|
+
version: '0.1.0',
|
|
12
|
+
baseDirectory: join(
|
|
13
|
+
dirname(dirname(fileURLToPath(import.meta.url))),
|
|
14
|
+
'project',
|
|
15
|
+
),
|
|
16
|
+
addOnsDirectories: [
|
|
17
|
+
join(dirname(dirname(fileURLToPath(import.meta.url))), 'add-ons'),
|
|
18
|
+
join(dirname(dirname(fileURLToPath(import.meta.url))), 'toolchains'),
|
|
19
|
+
join(dirname(dirname(fileURLToPath(import.meta.url))), 'examples'),
|
|
20
|
+
],
|
|
21
|
+
examplesDirectory: join(
|
|
22
|
+
dirname(dirname(fileURLToPath(import.meta.url))),
|
|
23
|
+
'examples',
|
|
24
|
+
),
|
|
25
|
+
})
|
|
26
|
+
}
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import { expect, test, beforeAll } from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
createApp,
|
|
5
|
+
createMemoryEnvironment,
|
|
6
|
+
finalizeAddOns,
|
|
7
|
+
getFrameworkById,
|
|
8
|
+
} from '@tanstack/cta-engine'
|
|
9
|
+
|
|
10
|
+
import type { AddOn, Options } from '@tanstack/cta-engine'
|
|
11
|
+
|
|
12
|
+
import { register as registerReactCra } from '../src/index.js'
|
|
13
|
+
|
|
14
|
+
import { cleanupOutput } from './test-utilities.js'
|
|
15
|
+
|
|
16
|
+
beforeAll(async () => {
|
|
17
|
+
await registerReactCra()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
async function createReactOptions(
|
|
21
|
+
addOns: Array<string> = [],
|
|
22
|
+
projectName: string = 'TEST',
|
|
23
|
+
) {
|
|
24
|
+
const framework = getFrameworkById('react-cra')!
|
|
25
|
+
|
|
26
|
+
let chosenAddOns: Array<AddOn> = []
|
|
27
|
+
let mode = 'code-router'
|
|
28
|
+
if (addOns) {
|
|
29
|
+
mode = 'file-router'
|
|
30
|
+
chosenAddOns = await finalizeAddOns(framework, mode, addOns)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return {
|
|
34
|
+
framework,
|
|
35
|
+
addOns: !!chosenAddOns.length,
|
|
36
|
+
chosenAddOns,
|
|
37
|
+
git: true,
|
|
38
|
+
mode,
|
|
39
|
+
packageManager: 'npm',
|
|
40
|
+
projectName,
|
|
41
|
+
targetDir: `/foo/bar/baz/${projectName}`,
|
|
42
|
+
tailwind: false,
|
|
43
|
+
typescript: false,
|
|
44
|
+
variableValues: {},
|
|
45
|
+
} as Options
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
test('code router in javascript on npm', async () => {
|
|
49
|
+
const { environment, output } = createMemoryEnvironment()
|
|
50
|
+
const options = await createReactOptions()
|
|
51
|
+
await createApp(environment, options)
|
|
52
|
+
const cleanedOutput = cleanupOutput(options, output)
|
|
53
|
+
await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
|
|
54
|
+
'./snapshots/react-cra/cr-js-npm.json',
|
|
55
|
+
)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('code router with form add-on on npm', async () => {
|
|
59
|
+
const { environment, output } = createMemoryEnvironment()
|
|
60
|
+
const options = await createReactOptions(['form'])
|
|
61
|
+
await createApp(environment, options)
|
|
62
|
+
const cleanedOutput = cleanupOutput(options, output)
|
|
63
|
+
await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
|
|
64
|
+
'./snapshots/react-cra/cr-js-form-npm.json',
|
|
65
|
+
)
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
test('code router in typescript on npm', async () => {
|
|
69
|
+
const { environment, output } = createMemoryEnvironment()
|
|
70
|
+
const options = {
|
|
71
|
+
...(await createReactOptions()),
|
|
72
|
+
typescript: true,
|
|
73
|
+
}
|
|
74
|
+
await createApp(environment, options)
|
|
75
|
+
const cleanedOutput = cleanupOutput(options, output)
|
|
76
|
+
await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
|
|
77
|
+
'./snapshots/react-cra/cr-ts-npm.json',
|
|
78
|
+
)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('file router on npm', async () => {
|
|
82
|
+
const { environment, output } = createMemoryEnvironment()
|
|
83
|
+
const options = {
|
|
84
|
+
...(await createReactOptions()),
|
|
85
|
+
mode: 'file-router',
|
|
86
|
+
typescript: true,
|
|
87
|
+
} as Options
|
|
88
|
+
await createApp(environment, options)
|
|
89
|
+
const cleanedOutput = cleanupOutput(options, output)
|
|
90
|
+
await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
|
|
91
|
+
'./snapshots/react-cra/fr-ts-npm.json',
|
|
92
|
+
)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
test('file router on npm with biome', async () => {
|
|
96
|
+
const { environment, output } = createMemoryEnvironment()
|
|
97
|
+
const options = {
|
|
98
|
+
...(await createReactOptions(['biome'])),
|
|
99
|
+
mode: 'file-router',
|
|
100
|
+
typescript: true,
|
|
101
|
+
} as Options
|
|
102
|
+
await createApp(environment, options)
|
|
103
|
+
const cleanedOutput = cleanupOutput(options, output)
|
|
104
|
+
await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
|
|
105
|
+
'./snapshots/react-cra/fr-ts-biome-npm.json',
|
|
106
|
+
)
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
test('file router with tailwind on npm', async () => {
|
|
110
|
+
const { environment, output } = createMemoryEnvironment()
|
|
111
|
+
const options = {
|
|
112
|
+
...(await createReactOptions()),
|
|
113
|
+
mode: 'file-router',
|
|
114
|
+
typescript: true,
|
|
115
|
+
tailwind: true,
|
|
116
|
+
} as Options
|
|
117
|
+
await createApp(environment, options)
|
|
118
|
+
const cleanedOutput = cleanupOutput(options, output)
|
|
119
|
+
await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
|
|
120
|
+
'./snapshots/react-cra/fr-ts-tw-npm.json',
|
|
121
|
+
)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
test('file router with add-on start on npm', async () => {
|
|
125
|
+
const { environment, output } = createMemoryEnvironment()
|
|
126
|
+
const options = {
|
|
127
|
+
...(await createReactOptions(['start'])),
|
|
128
|
+
tailwind: true,
|
|
129
|
+
typescript: true,
|
|
130
|
+
} as Options
|
|
131
|
+
await createApp(environment, options)
|
|
132
|
+
const cleanedOutput = cleanupOutput(options, output)
|
|
133
|
+
await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
|
|
134
|
+
'./snapshots/react-cra/cr-ts-start-npm.json',
|
|
135
|
+
)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('file router with add-on start on npm', async () => {
|
|
139
|
+
const { environment, output } = createMemoryEnvironment()
|
|
140
|
+
const options = {
|
|
141
|
+
...(await createReactOptions(['start', 'tanstack-query'])),
|
|
142
|
+
tailwind: true,
|
|
143
|
+
typescript: true,
|
|
144
|
+
} as Options
|
|
145
|
+
await createApp(environment, options)
|
|
146
|
+
const cleanedOutput = cleanupOutput(options, output)
|
|
147
|
+
await expect(JSON.stringify(cleanedOutput, null, 2)).toMatchFileSnapshot(
|
|
148
|
+
'./snapshots/react-cra/cr-ts-start-tanstack-query-npm.json',
|
|
149
|
+
)
|
|
150
|
+
})
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": {
|
|
3
|
+
".cta.json": "{\n \"addOns\": true,\n \"git\": true,\n \"mode\": \"file-router\",\n \"packageManager\": \"npm\",\n \"projectName\": \"TEST\",\n \"tailwind\": false,\n \"typescript\": false,\n \"variableValues\": {},\n \"version\": 1,\n \"framework\": \"react-cra\",\n \"existingAddOns\": [\n \"form\"\n ]\n}",
|
|
4
|
+
".gitignore": "node_modules\n.DS_Store\ndist\ndist-ssr\n*.local\n",
|
|
5
|
+
"/.vscode/settings.json": "{\n \"files.watcherExclude\": {\n \"**/routeTree.gen.ts\": true\n },\n \"search.exclude\": {\n \"**/routeTree.gen.ts\": true\n },\n \"files.readonlyInclude\": {\n \"**/routeTree.gen.ts\": true\n }\n}\n",
|
|
6
|
+
"/public/manifest.json": "{\n \"short_name\": \"TanStack App\",\n \"name\": \"Create TanStack App Sample\",\n \"icons\": [\n {\n \"src\": \"favicon.ico\",\n \"sizes\": \"64x64 32x32 24x24 16x16\",\n \"type\": \"image/x-icon\"\n },\n {\n \"src\": \"logo192.png\",\n \"type\": \"image/png\",\n \"sizes\": \"192x192\"\n },\n {\n \"src\": \"logo512.png\",\n \"type\": \"image/png\",\n \"sizes\": \"512x512\"\n }\n ],\n \"start_url\": \".\",\n \"display\": \"standalone\",\n \"theme_color\": \"#000000\",\n \"background_color\": \"#ffffff\"\n}\n",
|
|
7
|
+
"/public/robots.txt": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n",
|
|
8
|
+
"/src/App.css": ".App {\n text-align: center;\n}\n\n.App-logo {\n height: 40vmin;\n pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .App-logo {\n animation: App-logo-spin infinite 20s linear;\n }\n}\n\n.App-header {\n background-color: #282c34;\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n font-size: calc(10px + 2vmin);\n color: white;\n}\n\n.App-link {\n color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n}\n",
|
|
9
|
+
"/src/components/Header.jsx": "import { Link } from '@tanstack/react-router'\n\nexport default function Header() {\n return (\n <header className=\"p-2 flex gap-2 bg-white text-black justify-between\">\n <nav className=\"flex flex-row\">\n <div className=\"px-2 font-bold\">\n <Link to=\"/\">Home</Link>\n </div>\n\n <div className=\"px-2 font-bold\">\n <Link to=\"/demo/form/simple\">Simple Form</Link>\n </div>\n\n <div className=\"px-2 font-bold\">\n <Link to=\"/demo/form/address\">Address Form</Link>\n </div>\n </nav>\n </header>\n )\n}\n",
|
|
10
|
+
"/src/components/demo.FormComponents.jsx": "import { useStore } from '@tanstack/react-form'\n\nimport { useFieldContext, useFormContext } from '../hooks/demo.form-context'\n\nexport function SubscribeButton({ label }: { label: string }) {\n const form = useFormContext()\n return (\n <form.Subscribe selector={(state) => state.isSubmitting}>\n {(isSubmitting) => (\n <button\n type=\"submit\"\n disabled={isSubmitting}\n className=\"px-6 py-2 bg-indigo-600 text-white rounded-md hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-indigo-500 focus:ring-offset-2 transition-colors disabled:opacity-50\"\n >\n {label}\n </button>\n )}\n </form.Subscribe>\n )\n}\n\nfunction ErrorMessages({\n errors,\n}: {\n errors: Array<string | { message: string }>\n}) {\n return (\n <>\n {errors.map((error) => (\n <div\n key={typeof error === 'string' ? error : error.message}\n className=\"text-red-500 mt-1 font-bold\"\n >\n {typeof error === 'string' ? error : error.message}\n </div>\n ))}\n </>\n )\n}\n\nexport function TextField({\n label,\n placeholder,\n}: {\n label: string\n placeholder?: string\n}) {\n const field = useFieldContext<string>()\n const errors = useStore(field.store, (state) => state.meta.errors)\n\n return (\n <div>\n <label htmlFor={label} className=\"block font-bold mb-1 text-xl\">\n {label}\n <input\n value={field.state.value}\n placeholder={placeholder}\n onBlur={field.handleBlur}\n onChange={(e) => field.handleChange(e.target.value)}\n className=\"w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500\"\n />\n </label>\n {field.state.meta.isTouched && <ErrorMessages errors={errors} />}\n </div>\n )\n}\n\nexport function TextArea({\n label,\n rows = 3,\n}: {\n label: string\n rows?: number\n}) {\n const field = useFieldContext<string>()\n const errors = useStore(field.store, (state) => state.meta.errors)\n\n return (\n <div>\n <label htmlFor={label} className=\"block font-bold mb-1 text-xl\">\n {label}\n <textarea\n value={field.state.value}\n onBlur={field.handleBlur}\n rows={rows}\n onChange={(e) => field.handleChange(e.target.value)}\n className=\"w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500\"\n />\n </label>\n {field.state.meta.isTouched && <ErrorMessages errors={errors} />}\n </div>\n )\n}\n\nexport function Select({\n label,\n values,\n}: {\n label: string\n values: Array<{ label: string; value: string }>\n placeholder?: string\n}) {\n const field = useFieldContext<string>()\n const errors = useStore(field.store, (state) => state.meta.errors)\n\n return (\n <div>\n <label htmlFor={label} className=\"block font-bold mb-1 text-xl\">\n {label}\n </label>\n <select\n name={field.name}\n value={field.state.value}\n onBlur={field.handleBlur}\n onChange={(e) => field.handleChange(e.target.value)}\n className=\"w-full px-4 py-2 rounded-md border border-gray-300 focus:outline-none focus:ring-2 focus:ring-indigo-500\"\n >\n {values.map((value) => (\n <option key={value.value} value={value.value}>\n {value.label}\n </option>\n ))}\n </select>\n {field.state.meta.isTouched && <ErrorMessages errors={errors} />}\n </div>\n )\n}\n",
|
|
11
|
+
"/src/hooks/demo.form-context.js": "import { createFormHookContexts } from '@tanstack/react-form'\n\nexport const { fieldContext, useFieldContext, formContext, useFormContext } =\n createFormHookContexts()\n",
|
|
12
|
+
"/src/hooks/demo.form.js": "import { createFormHook } from '@tanstack/react-form'\n\nimport {\n Select,\n SubscribeButton,\n TextArea,\n TextField,\n} from '../components/demo.FormComponents'\nimport { fieldContext, formContext } from './demo.form-context'\n\nexport const { useAppForm } = createFormHook({\n fieldComponents: {\n TextField,\n Select,\n TextArea,\n },\n formComponents: {\n SubscribeButton,\n },\n fieldContext,\n formContext,\n})\n",
|
|
13
|
+
"/src/main.jsx": "import { StrictMode } from 'react'\nimport ReactDOM from 'react-dom/client'\nimport { RouterProvider, createRouter } from '@tanstack/react-router'\n\n// Import the generated route tree\nimport { routeTree } from './routeTree.gen'\n\nimport './styles.css'\nimport reportWebVitals from './reportWebVitals.js'\n\n// Create a new router instance\nconst router = createRouter({\n routeTree,\n context: {},\n defaultPreload: 'intent',\n scrollRestoration: true,\n defaultStructuralSharing: true,\n defaultPreloadStaleTime: 0,\n})\n\n// Register the router instance for type safety\ndeclare module '@tanstack/react-router' {\n interface Register {\n router: typeof router\n }\n}\n\n// Render the app\nconst rootElement = document.getElementById('app')\nif (rootElement && !rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement)\n root.render(\n <StrictMode>\n <RouterProvider router={router} />\n </StrictMode>,\n )\n}\n\n// If you want to start measuring performance in your app, pass a function\n// to log results (for example: reportWebVitals(console.log))\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\nreportWebVitals()\n",
|
|
14
|
+
"/src/reportWebVitals.js": "const reportWebVitals = (onPerfEntry) => {\n if (onPerfEntry && onPerfEntry instanceof Function) {\n import('web-vitals').then(({ onCLS, onINP, onFCP, onLCP, onTTFB }) => {\n onCLS(onPerfEntry)\n onINP(onPerfEntry)\n onFCP(onPerfEntry)\n onLCP(onPerfEntry)\n onTTFB(onPerfEntry)\n })\n }\n}\n\nexport default reportWebVitals\n",
|
|
15
|
+
"/src/routes/__root.jsx": "import { Outlet, createRootRoute } from '@tanstack/react-router'\nimport { TanStackRouterDevtools } from '@tanstack/react-router-devtools'\n\nimport Header from '../components/Header'\n\nexport const Route = createRootRoute({\n component: () => (\n <>\n <Header />\n\n <Outlet />\n <TanStackRouterDevtools />\n </>\n ),\n})\n",
|
|
16
|
+
"/src/routes/demo.form.address.jsx": "import { createFileRoute } from '@tanstack/react-router'\n\nimport { useAppForm } from '../hooks/demo.form'\n\nexport const Route = createFileRoute('/demo/form')({\n component: AddressForm,\n})\n\nfunction AddressForm() {\n const form = useAppForm({\n defaultValues: {\n fullName: '',\n email: '',\n address: {\n street: '',\n city: '',\n state: '',\n zipCode: '',\n country: '',\n },\n phone: '',\n },\n validators: {\n onBlur: ({ value }) => {\n const errors = {\n fields: {},\n } as {\n fields: Record<string, string>\n }\n if (value.fullName.trim().length === 0) {\n errors.fields.fullName = 'Full name is required'\n }\n return errors\n },\n },\n onSubmit: ({ value }) => {\n console.log(value)\n // Show success message\n alert('Form submitted successfully!')\n },\n })\n\n return (\n <div\n className=\"flex items-center justify-center min-h-screen bg-gradient-to-br from-purple-100 to-blue-100 p-4 text-white\"\n style={{\n backgroundImage:\n 'radial-gradient(50% 50% at 5% 40%, #f4a460 0%, #8b4513 70%, #1a0f0a 100%)',\n }}\n >\n <div className=\"w-full max-w-2xl p-8 rounded-xl backdrop-blur-md bg-black/50 shadow-xl border-8 border-black/10\">\n <form\n onSubmit={(e) => {\n e.preventDefault()\n e.stopPropagation()\n form.handleSubmit()\n }}\n className=\"space-y-6\"\n >\n <form.AppField name=\"fullName\">\n {(field) => <field.TextField label=\"Full Name\" />}\n </form.AppField>\n\n <form.AppField\n name=\"email\"\n validators={{\n onBlur: ({ value }) => {\n if (!value || value.trim().length === 0) {\n return 'Email is required'\n }\n if (!/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}$/i.test(value)) {\n return 'Invalid email address'\n }\n return undefined\n },\n }}\n >\n {(field) => <field.TextField label=\"Email\" />}\n </form.AppField>\n\n <form.AppField\n name=\"address.street\"\n validators={{\n onBlur: ({ value }) => {\n if (!value || value.trim().length === 0) {\n return 'Street address is required'\n }\n return undefined\n },\n }}\n >\n {(field) => <field.TextField label=\"Street Address\" />}\n </form.AppField>\n\n <div className=\"grid grid-cols-1 md:grid-cols-3 gap-4\">\n <form.AppField\n name=\"address.city\"\n validators={{\n onBlur: ({ value }) => {\n if (!value || value.trim().length === 0) {\n return 'City is required'\n }\n return undefined\n },\n }}\n >\n {(field) => <field.TextField label=\"City\" />}\n </form.AppField>\n <form.AppField\n name=\"address.state\"\n validators={{\n onBlur: ({ value }) => {\n if (!value || value.trim().length === 0) {\n return 'State is required'\n }\n return undefined\n },\n }}\n >\n {(field) => <field.TextField label=\"State\" />}\n </form.AppField>\n <form.AppField\n name=\"address.zipCode\"\n validators={{\n onBlur: ({ value }) => {\n if (!value || value.trim().length === 0) {\n return 'Zip code is required'\n }\n if (!/^\\d{5}(-\\d{4})?$/.test(value)) {\n return 'Invalid zip code format'\n }\n return undefined\n },\n }}\n >\n {(field) => <field.TextField label=\"Zip Code\" />}\n </form.AppField>\n </div>\n\n <form.AppField\n name=\"address.country\"\n validators={{\n onBlur: ({ value }) => {\n if (!value || value.trim().length === 0) {\n return 'Country is required'\n }\n return undefined\n },\n }}\n >\n {(field) => (\n <field.Select\n label=\"Country\"\n values={[\n { label: 'United States', value: 'US' },\n { label: 'Canada', value: 'CA' },\n { label: 'United Kingdom', value: 'UK' },\n { label: 'Australia', value: 'AU' },\n { label: 'Germany', value: 'DE' },\n { label: 'France', value: 'FR' },\n { label: 'Japan', value: 'JP' },\n ]}\n placeholder=\"Select a country\"\n />\n )}\n </form.AppField>\n\n <form.AppField\n name=\"phone\"\n validators={{\n onBlur: ({ value }) => {\n if (!value || value.trim().length === 0) {\n return 'Phone number is required'\n }\n if (\n !/^(\\+\\d{1,3})?\\s?\\(?\\d{3}\\)?[\\s.-]?\\d{3}[\\s.-]?\\d{4}$/.test(\n value,\n )\n ) {\n return 'Invalid phone number format'\n }\n return undefined\n },\n }}\n >\n {(field) => (\n <field.TextField label=\"Phone\" placeholder=\"123-456-7890\" />\n )}\n </form.AppField>\n\n <div className=\"flex justify-end\">\n <form.AppForm>\n <form.SubscribeButton label=\"Submit\" />\n </form.AppForm>\n </div>\n </form>\n </div>\n </div>\n )\n}\n",
|
|
17
|
+
"/src/routes/demo.form.simple.jsx": "import { createFileRoute } from '@tanstack/react-router'\nimport { z } from 'zod'\n\nimport { useAppForm } from '../hooks/demo.form'\n\nexport const Route = createFileRoute('/demo/form')({\n component: SimpleForm,\n})\n\nconst schema = z.object({\n title: z.string().min(1, 'Title is required'),\n description: z.string().min(1, 'Description is required'),\n})\n\nfunction SimpleForm() {\n const form = useAppForm({\n defaultValues: {\n title: '',\n description: '',\n },\n validators: {\n onBlur: schema,\n },\n onSubmit: ({ value }) => {\n console.log(value)\n // Show success message\n alert('Form submitted successfully!')\n },\n })\n\n return (\n <div\n className=\"flex items-center justify-center min-h-screen bg-gradient-to-br from-purple-100 to-blue-100 p-4 text-white\"\n style={{\n backgroundImage:\n 'radial-gradient(50% 50% at 5% 40%, #add8e6 0%, #0000ff 70%, #00008b 100%)',\n }}\n >\n <div className=\"w-full max-w-2xl p-8 rounded-xl backdrop-blur-md bg-black/50 shadow-xl border-8 border-black/10\">\n <form\n onSubmit={(e) => {\n e.preventDefault()\n e.stopPropagation()\n form.handleSubmit()\n }}\n className=\"space-y-6\"\n >\n <form.AppField name=\"title\">\n {(field) => <field.TextField label=\"Title\" />}\n </form.AppField>\n\n <form.AppField name=\"description\">\n {(field) => <field.TextArea label=\"Description\" />}\n </form.AppField>\n\n <div className=\"flex justify-end\">\n <form.AppForm>\n <form.SubscribeButton label=\"Submit\" />\n </form.AppForm>\n </div>\n </form>\n </div>\n </div>\n )\n}\n",
|
|
18
|
+
"/src/routes/index.jsx": "import { createFileRoute } from '@tanstack/react-router'\nimport logo from '../logo.svg'\nimport '../App.css'\n\nexport const Route = createFileRoute('/')({\n component: App,\n})\n\nfunction App() {\n return (\n <div className=\"App\">\n <header className=\"App-header\">\n <img src={logo} className=\"App-logo\" alt=\"logo\" />\n <p>\n Edit <code>src/routes/index.tsx</code> and save to reload.\n </p>\n <a\n className=\"App-link\"\n href=\"https://reactjs.org\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn React\n </a>\n <a\n className=\"App-link\"\n href=\"https://tanstack.com\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn TanStack\n </a>\n </header>\n </div>\n )\n}\n",
|
|
19
|
+
"/src/styles.css": "\nbody {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\",\n \"Ubuntu\", \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\",\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, \"Courier New\",\n monospace;\n}\n",
|
|
20
|
+
"README.md": "Welcome to your new TanStack app! \n\n# Getting Started\n\nTo run this application:\n\n```bash\nnpm install\nnpm run start \n```\n\n# Building For Production\n\nTo build this application for production:\n\n```bash\nnpm run build\n```\n\n## Testing\n\nThis project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:\n\n```bash\nnpm run test\n```\n\n## Styling\n\nThis project uses CSS for styling.\n\n\n\n\n## Routing\nThis project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means that the routes are managed as files in `src/routes`.\n\n### Adding A Route\n\nTo add a new route to your application just add another a new file in the `./src/routes` directory.\n\nTanStack will automatically generate the content of the route file for you.\n\nNow that you have two routes you can use a `Link` component to navigate between them.\n\n### Adding Links\n\nTo use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.\n\n```tsx\nimport { Link } from \"@tanstack/react-router\";\n```\n\nThen anywhere in your JSX you can use it like so:\n\n```tsx\n<Link to=\"/about\">About</Link>\n```\n\nThis will create a link that will navigate to the `/about` route.\n\nMore information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).\n\n### Using A Layout\n\nIn the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes. The route content will appear in the JSX where you use the `<Outlet />` component.\n\nHere is an example layout that includes a header:\n\n```tsx\nimport { Outlet, createRootRoute } from '@tanstack/react-router'\nimport { TanStackRouterDevtools } from '@tanstack/react-router-devtools'\n\nimport { Link } from \"@tanstack/react-router\";\n\nexport const Route = createRootRoute({\n component: () => (\n <>\n <header>\n <nav>\n <Link to=\"/\">Home</Link>\n <Link to=\"/about\">About</Link>\n </nav>\n </header>\n <Outlet />\n <TanStackRouterDevtools />\n </>\n ),\n})\n```\n\nThe `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.\n\nMore information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).\n\n\n## Data Fetching\n\nThere 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.\n\nFor example:\n\n```tsx\nconst peopleRoute = createRoute({\n getParentRoute: () => rootRoute,\n path: \"/people\",\n loader: async () => {\n const response = await fetch(\"https://swapi.dev/api/people\");\n return response.json();\n },\n component: () => {\n const data = peopleRoute.useLoaderData();\n return (\n <ul>\n {data.results.map((person) => (\n <li key={person.name}>{person.name}</li>\n ))}\n </ul>\n );\n },\n});\n```\n\nLoaders 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).\n\n### React-Query\n\nReact-Query is an excellent addition or alternative to route loading and integrating it into you application is a breeze.\n\nFirst add your dependencies:\n\n```bash\nnpm install @tanstack/react-query @tanstack/react-query-devtools\n```\n\nNext we'll need to create a query client and provider. We recommend putting those in `main.jsx`.\n\n```tsx\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\n\n// ...\n\nconst queryClient = new QueryClient();\n\n// ...\n\nif (!rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement);\n\n root.render(\n <QueryClientProvider client={queryClient}>\n <RouterProvider router={router} />\n </QueryClientProvider>\n );\n}\n```\n\nYou can also add TanStack Query Devtools to the root route (optional).\n\n```tsx\nimport { ReactQueryDevtools } from \"@tanstack/react-query-devtools\";\n\nconst rootRoute = createRootRoute({\n component: () => (\n <>\n <Outlet />\n <ReactQueryDevtools buttonPosition=\"top-right\" />\n <TanStackRouterDevtools />\n </>\n ),\n});\n```\n\nNow you can use `useQuery` to fetch your data.\n\n```tsx\nimport { useQuery } from \"@tanstack/react-query\";\n\nimport \"./App.css\";\n\nfunction App() {\n const { data } = useQuery({\n queryKey: [\"people\"],\n queryFn: () =>\n fetch(\"https://swapi.dev/api/people\")\n .then((res) => res.json())\n .then((data) => data.results),\n initialData: [],\n });\n\n return (\n <div>\n <ul>\n {data.map((person) => (\n <li key={person.name}>{person.name}</li>\n ))}\n </ul>\n </div>\n );\n}\n\nexport default App;\n```\n\nYou 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).\n\n## State Management\n\nAnother 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.\n\nFirst you need to add TanStack Store as a dependency:\n\n```bash\nnpm install @tanstack/store\n```\n\nNow let's create a simple counter in the `src/App.jsx` file as a demonstration.\n\n```tsx\nimport { useStore } from \"@tanstack/react-store\";\nimport { Store } from \"@tanstack/store\";\nimport \"./App.css\";\n\nconst countStore = new Store(0);\n\nfunction App() {\n const count = useStore(countStore);\n return (\n <div>\n <button onClick={() => countStore.setState((n) => n + 1)}>\n Increment - {count}\n </button>\n </div>\n );\n}\n\nexport default App;\n```\n\nOne 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.\n\nLet's check this out by doubling the count using derived state.\n\n```tsx\nimport { useStore } from \"@tanstack/react-store\";\nimport { Store, Derived } from \"@tanstack/store\";\nimport \"./App.css\";\n\nconst countStore = new Store(0);\n\nconst doubledStore = new Derived({\n fn: () => countStore.state * 2,\n deps: [countStore],\n});\ndoubledStore.mount();\n\nfunction App() {\n const count = useStore(countStore);\n const doubledCount = useStore(doubledStore);\n\n return (\n <div>\n <button onClick={() => countStore.setState((n) => n + 1)}>\n Increment - {count}\n </button>\n <div>Doubled - {doubledCount}</div>\n </div>\n );\n}\n\nexport default App;\n```\n\nWe 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.\n\nOnce 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.\n\nYou can find out everything you need to know on how to use TanStack Store in the [TanStack Store documentation](https://tanstack.com/store/latest).\n\n# Demo files\n\nFiles 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.\n\n# Learn More\n\nYou can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).\n",
|
|
21
|
+
"index.html": "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <link rel=\"icon\" href=\"/favicon.ico\" />\n <meta name=\"theme-color\" content=\"#000000\" />\n <meta\n name=\"description\"\n content=\"Web site created using create-tsrouter-app\"\n />\n <link rel=\"apple-touch-icon\" href=\"/logo192.png\" />\n <link rel=\"manifest\" href=\"/manifest.json\" />\n <title>Create TanStack App - TEST</title>\n </head>\n <body>\n <div id=\"app\"></div>\n <script type=\"module\" src=\"/src/main.jsx\"></script>\n </body>\n</html>\n",
|
|
22
|
+
"package.json": "{\n \"name\": \"TEST\",\n \"private\": true,\n \"type\": \"module\",\n \"scripts\": {\n \"dev\": \"vite --port 3000\",\n \"start\": \"vite --port 3000\",\n \"build\": \"vite build && tsc\",\n \"serve\": \"vite preview\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@tanstack/react-form\": \"^1.0.0\",\n \"@tanstack/react-router\": \"^1.114.3\",\n \"@tanstack/react-router-devtools\": \"^1.114.3\",\n \"@tanstack/router-plugin\": \"^1.114.3\",\n \"react\": \"^19.0.0\",\n \"react-dom\": \"^19.0.0\",\n \"zod\": \"^3.24.2\"\n },\n \"devDependencies\": {\n \"@testing-library/dom\": \"^10.4.0\",\n \"@testing-library/react\": \"^16.2.0\",\n \"@types/react\": \"^19.0.8\",\n \"@types/react-dom\": \"^19.0.3\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^26.0.0\",\n \"typescript\": \"^5.7.2\",\n \"vite\": \"^6.1.0\",\n \"vitest\": \"^3.0.5\",\n \"web-vitals\": \"^4.2.4\"\n }\n}",
|
|
23
|
+
"vite.config.js": "import { defineConfig } from \"vite\";\nimport viteReact from \"@vitejs/plugin-react\";\nimport { TanStackRouterVite } from \"@tanstack/router-plugin/vite\";\nimport { resolve } from \"node:path\";\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [TanStackRouterVite({ autoCodeSplitting: true }), viteReact()],\n test: {\n globals: true,\n environment: \"jsdom\",\n },\n resolve: {\n alias: {\n '@': resolve(__dirname, './src'),\n },\n }\n});\n"
|
|
24
|
+
},
|
|
25
|
+
"commands": [
|
|
26
|
+
"git init",
|
|
27
|
+
"npm install"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": {
|
|
3
|
+
".cta.json": "{\n \"addOns\": false,\n \"git\": true,\n \"mode\": \"file-router\",\n \"packageManager\": \"npm\",\n \"projectName\": \"TEST\",\n \"tailwind\": false,\n \"typescript\": false,\n \"variableValues\": {},\n \"version\": 1,\n \"framework\": \"react-cra\",\n \"existingAddOns\": []\n}",
|
|
4
|
+
".gitignore": "node_modules\n.DS_Store\ndist\ndist-ssr\n*.local\n",
|
|
5
|
+
"/.vscode/settings.json": "{\n \"files.watcherExclude\": {\n \"**/routeTree.gen.ts\": true\n },\n \"search.exclude\": {\n \"**/routeTree.gen.ts\": true\n },\n \"files.readonlyInclude\": {\n \"**/routeTree.gen.ts\": true\n }\n}\n",
|
|
6
|
+
"/public/manifest.json": "{\n \"short_name\": \"TanStack App\",\n \"name\": \"Create TanStack App Sample\",\n \"icons\": [\n {\n \"src\": \"favicon.ico\",\n \"sizes\": \"64x64 32x32 24x24 16x16\",\n \"type\": \"image/x-icon\"\n },\n {\n \"src\": \"logo192.png\",\n \"type\": \"image/png\",\n \"sizes\": \"192x192\"\n },\n {\n \"src\": \"logo512.png\",\n \"type\": \"image/png\",\n \"sizes\": \"512x512\"\n }\n ],\n \"start_url\": \".\",\n \"display\": \"standalone\",\n \"theme_color\": \"#000000\",\n \"background_color\": \"#ffffff\"\n}\n",
|
|
7
|
+
"/public/robots.txt": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n",
|
|
8
|
+
"/src/App.css": ".App {\n text-align: center;\n}\n\n.App-logo {\n height: 40vmin;\n pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .App-logo {\n animation: App-logo-spin infinite 20s linear;\n }\n}\n\n.App-header {\n background-color: #282c34;\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n font-size: calc(10px + 2vmin);\n color: white;\n}\n\n.App-link {\n color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n}\n",
|
|
9
|
+
"/src/main.jsx": "import { StrictMode } from 'react'\nimport ReactDOM from 'react-dom/client'\nimport { RouterProvider, createRouter } from '@tanstack/react-router'\n\n// Import the generated route tree\nimport { routeTree } from './routeTree.gen'\n\nimport './styles.css'\nimport reportWebVitals from './reportWebVitals.js'\n\n// Create a new router instance\nconst router = createRouter({\n routeTree,\n context: {},\n defaultPreload: 'intent',\n scrollRestoration: true,\n defaultStructuralSharing: true,\n defaultPreloadStaleTime: 0,\n})\n\n// Register the router instance for type safety\ndeclare module '@tanstack/react-router' {\n interface Register {\n router: typeof router\n }\n}\n\n// Render the app\nconst rootElement = document.getElementById('app')\nif (rootElement && !rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement)\n root.render(\n <StrictMode>\n <RouterProvider router={router} />\n </StrictMode>,\n )\n}\n\n// If you want to start measuring performance in your app, pass a function\n// to log results (for example: reportWebVitals(console.log))\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\nreportWebVitals()\n",
|
|
10
|
+
"/src/reportWebVitals.js": "const reportWebVitals = (onPerfEntry) => {\n if (onPerfEntry && onPerfEntry instanceof Function) {\n import('web-vitals').then(({ onCLS, onINP, onFCP, onLCP, onTTFB }) => {\n onCLS(onPerfEntry)\n onINP(onPerfEntry)\n onFCP(onPerfEntry)\n onLCP(onPerfEntry)\n onTTFB(onPerfEntry)\n })\n }\n}\n\nexport default reportWebVitals\n",
|
|
11
|
+
"/src/routes/__root.jsx": "import { Outlet, createRootRoute } from '@tanstack/react-router'\nimport { TanStackRouterDevtools } from '@tanstack/react-router-devtools'\n\nexport const Route = createRootRoute({\n component: () => (\n <>\n <Outlet />\n <TanStackRouterDevtools />\n </>\n ),\n})\n",
|
|
12
|
+
"/src/routes/index.jsx": "import { createFileRoute } from '@tanstack/react-router'\nimport logo from '../logo.svg'\nimport '../App.css'\n\nexport const Route = createFileRoute('/')({\n component: App,\n})\n\nfunction App() {\n return (\n <div className=\"App\">\n <header className=\"App-header\">\n <img src={logo} className=\"App-logo\" alt=\"logo\" />\n <p>\n Edit <code>src/routes/index.tsx</code> and save to reload.\n </p>\n <a\n className=\"App-link\"\n href=\"https://reactjs.org\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn React\n </a>\n <a\n className=\"App-link\"\n href=\"https://tanstack.com\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn TanStack\n </a>\n </header>\n </div>\n )\n}\n",
|
|
13
|
+
"/src/styles.css": "\nbody {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\",\n \"Ubuntu\", \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\",\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, \"Courier New\",\n monospace;\n}\n",
|
|
14
|
+
"README.md": "Welcome to your new TanStack app! \n\n# Getting Started\n\nTo run this application:\n\n```bash\nnpm install\nnpm run start \n```\n\n# Building For Production\n\nTo build this application for production:\n\n```bash\nnpm run build\n```\n\n## Testing\n\nThis project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:\n\n```bash\nnpm run test\n```\n\n## Styling\n\nThis project uses CSS for styling.\n\n\n\n\n## Routing\nThis project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means that the routes are managed as files in `src/routes`.\n\n### Adding A Route\n\nTo add a new route to your application just add another a new file in the `./src/routes` directory.\n\nTanStack will automatically generate the content of the route file for you.\n\nNow that you have two routes you can use a `Link` component to navigate between them.\n\n### Adding Links\n\nTo use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.\n\n```tsx\nimport { Link } from \"@tanstack/react-router\";\n```\n\nThen anywhere in your JSX you can use it like so:\n\n```tsx\n<Link to=\"/about\">About</Link>\n```\n\nThis will create a link that will navigate to the `/about` route.\n\nMore information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).\n\n### Using A Layout\n\nIn the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes. The route content will appear in the JSX where you use the `<Outlet />` component.\n\nHere is an example layout that includes a header:\n\n```tsx\nimport { Outlet, createRootRoute } from '@tanstack/react-router'\nimport { TanStackRouterDevtools } from '@tanstack/react-router-devtools'\n\nimport { Link } from \"@tanstack/react-router\";\n\nexport const Route = createRootRoute({\n component: () => (\n <>\n <header>\n <nav>\n <Link to=\"/\">Home</Link>\n <Link to=\"/about\">About</Link>\n </nav>\n </header>\n <Outlet />\n <TanStackRouterDevtools />\n </>\n ),\n})\n```\n\nThe `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.\n\nMore information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).\n\n\n## Data Fetching\n\nThere 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.\n\nFor example:\n\n```tsx\nconst peopleRoute = createRoute({\n getParentRoute: () => rootRoute,\n path: \"/people\",\n loader: async () => {\n const response = await fetch(\"https://swapi.dev/api/people\");\n return response.json();\n },\n component: () => {\n const data = peopleRoute.useLoaderData();\n return (\n <ul>\n {data.results.map((person) => (\n <li key={person.name}>{person.name}</li>\n ))}\n </ul>\n );\n },\n});\n```\n\nLoaders 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).\n\n### React-Query\n\nReact-Query is an excellent addition or alternative to route loading and integrating it into you application is a breeze.\n\nFirst add your dependencies:\n\n```bash\nnpm install @tanstack/react-query @tanstack/react-query-devtools\n```\n\nNext we'll need to create a query client and provider. We recommend putting those in `main.jsx`.\n\n```tsx\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\n\n// ...\n\nconst queryClient = new QueryClient();\n\n// ...\n\nif (!rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement);\n\n root.render(\n <QueryClientProvider client={queryClient}>\n <RouterProvider router={router} />\n </QueryClientProvider>\n );\n}\n```\n\nYou can also add TanStack Query Devtools to the root route (optional).\n\n```tsx\nimport { ReactQueryDevtools } from \"@tanstack/react-query-devtools\";\n\nconst rootRoute = createRootRoute({\n component: () => (\n <>\n <Outlet />\n <ReactQueryDevtools buttonPosition=\"top-right\" />\n <TanStackRouterDevtools />\n </>\n ),\n});\n```\n\nNow you can use `useQuery` to fetch your data.\n\n```tsx\nimport { useQuery } from \"@tanstack/react-query\";\n\nimport \"./App.css\";\n\nfunction App() {\n const { data } = useQuery({\n queryKey: [\"people\"],\n queryFn: () =>\n fetch(\"https://swapi.dev/api/people\")\n .then((res) => res.json())\n .then((data) => data.results),\n initialData: [],\n });\n\n return (\n <div>\n <ul>\n {data.map((person) => (\n <li key={person.name}>{person.name}</li>\n ))}\n </ul>\n </div>\n );\n}\n\nexport default App;\n```\n\nYou 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).\n\n## State Management\n\nAnother 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.\n\nFirst you need to add TanStack Store as a dependency:\n\n```bash\nnpm install @tanstack/store\n```\n\nNow let's create a simple counter in the `src/App.jsx` file as a demonstration.\n\n```tsx\nimport { useStore } from \"@tanstack/react-store\";\nimport { Store } from \"@tanstack/store\";\nimport \"./App.css\";\n\nconst countStore = new Store(0);\n\nfunction App() {\n const count = useStore(countStore);\n return (\n <div>\n <button onClick={() => countStore.setState((n) => n + 1)}>\n Increment - {count}\n </button>\n </div>\n );\n}\n\nexport default App;\n```\n\nOne 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.\n\nLet's check this out by doubling the count using derived state.\n\n```tsx\nimport { useStore } from \"@tanstack/react-store\";\nimport { Store, Derived } from \"@tanstack/store\";\nimport \"./App.css\";\n\nconst countStore = new Store(0);\n\nconst doubledStore = new Derived({\n fn: () => countStore.state * 2,\n deps: [countStore],\n});\ndoubledStore.mount();\n\nfunction App() {\n const count = useStore(countStore);\n const doubledCount = useStore(doubledStore);\n\n return (\n <div>\n <button onClick={() => countStore.setState((n) => n + 1)}>\n Increment - {count}\n </button>\n <div>Doubled - {doubledCount}</div>\n </div>\n );\n}\n\nexport default App;\n```\n\nWe 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.\n\nOnce 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.\n\nYou can find out everything you need to know on how to use TanStack Store in the [TanStack Store documentation](https://tanstack.com/store/latest).\n\n# Demo files\n\nFiles 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.\n\n# Learn More\n\nYou can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).\n",
|
|
15
|
+
"index.html": "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <link rel=\"icon\" href=\"/favicon.ico\" />\n <meta name=\"theme-color\" content=\"#000000\" />\n <meta\n name=\"description\"\n content=\"Web site created using create-tsrouter-app\"\n />\n <link rel=\"apple-touch-icon\" href=\"/logo192.png\" />\n <link rel=\"manifest\" href=\"/manifest.json\" />\n <title>Create TanStack App - TEST</title>\n </head>\n <body>\n <div id=\"app\"></div>\n <script type=\"module\" src=\"/src/main.jsx\"></script>\n </body>\n</html>\n",
|
|
16
|
+
"package.json": "{\n \"name\": \"TEST\",\n \"private\": true,\n \"type\": \"module\",\n \"scripts\": {\n \"dev\": \"vite --port 3000\",\n \"start\": \"vite --port 3000\",\n \"build\": \"vite build && tsc\",\n \"serve\": \"vite preview\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@tanstack/react-router\": \"^1.114.3\",\n \"@tanstack/react-router-devtools\": \"^1.114.3\",\n \"@tanstack/router-plugin\": \"^1.114.3\",\n \"react\": \"^19.0.0\",\n \"react-dom\": \"^19.0.0\"\n },\n \"devDependencies\": {\n \"@testing-library/dom\": \"^10.4.0\",\n \"@testing-library/react\": \"^16.2.0\",\n \"@types/react\": \"^19.0.8\",\n \"@types/react-dom\": \"^19.0.3\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^26.0.0\",\n \"typescript\": \"^5.7.2\",\n \"vite\": \"^6.1.0\",\n \"vitest\": \"^3.0.5\",\n \"web-vitals\": \"^4.2.4\"\n }\n}",
|
|
17
|
+
"vite.config.js": "import { defineConfig } from \"vite\";\nimport viteReact from \"@vitejs/plugin-react\";\nimport { TanStackRouterVite } from \"@tanstack/router-plugin/vite\";\nimport { resolve } from \"node:path\";\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [TanStackRouterVite({ autoCodeSplitting: true }), viteReact()],\n test: {\n globals: true,\n environment: \"jsdom\",\n },\n resolve: {\n alias: {\n '@': resolve(__dirname, './src'),\n },\n }\n});\n"
|
|
18
|
+
},
|
|
19
|
+
"commands": [
|
|
20
|
+
"git init",
|
|
21
|
+
"npm install"
|
|
22
|
+
]
|
|
23
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": {
|
|
3
|
+
".cta.json": "{\n \"addOns\": false,\n \"git\": true,\n \"mode\": \"file-router\",\n \"packageManager\": \"npm\",\n \"projectName\": \"TEST\",\n \"tailwind\": false,\n \"typescript\": true,\n \"variableValues\": {},\n \"version\": 1,\n \"framework\": \"react-cra\",\n \"existingAddOns\": []\n}",
|
|
4
|
+
".gitignore": "node_modules\n.DS_Store\ndist\ndist-ssr\n*.local\n",
|
|
5
|
+
"/.vscode/settings.json": "{\n \"files.watcherExclude\": {\n \"**/routeTree.gen.ts\": true\n },\n \"search.exclude\": {\n \"**/routeTree.gen.ts\": true\n },\n \"files.readonlyInclude\": {\n \"**/routeTree.gen.ts\": true\n }\n}\n",
|
|
6
|
+
"/public/manifest.json": "{\n \"short_name\": \"TanStack App\",\n \"name\": \"Create TanStack App Sample\",\n \"icons\": [\n {\n \"src\": \"favicon.ico\",\n \"sizes\": \"64x64 32x32 24x24 16x16\",\n \"type\": \"image/x-icon\"\n },\n {\n \"src\": \"logo192.png\",\n \"type\": \"image/png\",\n \"sizes\": \"192x192\"\n },\n {\n \"src\": \"logo512.png\",\n \"type\": \"image/png\",\n \"sizes\": \"512x512\"\n }\n ],\n \"start_url\": \".\",\n \"display\": \"standalone\",\n \"theme_color\": \"#000000\",\n \"background_color\": \"#ffffff\"\n}\n",
|
|
7
|
+
"/public/robots.txt": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n",
|
|
8
|
+
"/src/App.css": ".App {\n text-align: center;\n}\n\n.App-logo {\n height: 40vmin;\n pointer-events: none;\n}\n\n@media (prefers-reduced-motion: no-preference) {\n .App-logo {\n animation: App-logo-spin infinite 20s linear;\n }\n}\n\n.App-header {\n background-color: #282c34;\n min-height: 100vh;\n display: flex;\n flex-direction: column;\n align-items: center;\n justify-content: center;\n font-size: calc(10px + 2vmin);\n color: white;\n}\n\n.App-link {\n color: #61dafb;\n}\n\n@keyframes App-logo-spin {\n from {\n transform: rotate(0deg);\n }\n to {\n transform: rotate(360deg);\n }\n}\n",
|
|
9
|
+
"/src/main.tsx": "import { StrictMode } from 'react'\nimport ReactDOM from 'react-dom/client'\nimport { RouterProvider, createRouter } from '@tanstack/react-router'\n\n// Import the generated route tree\nimport { routeTree } from './routeTree.gen'\n\nimport './styles.css'\nimport reportWebVitals from './reportWebVitals.ts'\n\n// Create a new router instance\nconst router = createRouter({\n routeTree,\n context: {},\n defaultPreload: 'intent',\n scrollRestoration: true,\n defaultStructuralSharing: true,\n defaultPreloadStaleTime: 0,\n})\n\n// Register the router instance for type safety\ndeclare module '@tanstack/react-router' {\n interface Register {\n router: typeof router\n }\n}\n\n// Render the app\nconst rootElement = document.getElementById('app')\nif (rootElement && !rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement)\n root.render(\n <StrictMode>\n <RouterProvider router={router} />\n </StrictMode>,\n )\n}\n\n// If you want to start measuring performance in your app, pass a function\n// to log results (for example: reportWebVitals(console.log))\n// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals\nreportWebVitals()\n",
|
|
10
|
+
"/src/reportWebVitals.ts": "const reportWebVitals = (onPerfEntry?: () => void) => {\n if (onPerfEntry && onPerfEntry instanceof Function) {\n import('web-vitals').then(({ onCLS, onINP, onFCP, onLCP, onTTFB }) => {\n onCLS(onPerfEntry)\n onINP(onPerfEntry)\n onFCP(onPerfEntry)\n onLCP(onPerfEntry)\n onTTFB(onPerfEntry)\n })\n }\n}\n\nexport default reportWebVitals\n",
|
|
11
|
+
"/src/routes/__root.tsx": "import { Outlet, createRootRoute } from '@tanstack/react-router'\nimport { TanStackRouterDevtools } from '@tanstack/react-router-devtools'\n\nexport const Route = createRootRoute({\n component: () => (\n <>\n <Outlet />\n <TanStackRouterDevtools />\n </>\n ),\n})\n",
|
|
12
|
+
"/src/routes/index.tsx": "import { createFileRoute } from '@tanstack/react-router'\nimport logo from '../logo.svg'\nimport '../App.css'\n\nexport const Route = createFileRoute('/')({\n component: App,\n})\n\nfunction App() {\n return (\n <div className=\"App\">\n <header className=\"App-header\">\n <img src={logo} className=\"App-logo\" alt=\"logo\" />\n <p>\n Edit <code>src/routes/index.tsx</code> and save to reload.\n </p>\n <a\n className=\"App-link\"\n href=\"https://reactjs.org\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn React\n </a>\n <a\n className=\"App-link\"\n href=\"https://tanstack.com\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn TanStack\n </a>\n </header>\n </div>\n )\n}\n",
|
|
13
|
+
"/src/styles.css": "\nbody {\n margin: 0;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\",\n \"Ubuntu\", \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\",\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, \"Courier New\",\n monospace;\n}\n",
|
|
14
|
+
"README.md": "Welcome to your new TanStack app! \n\n# Getting Started\n\nTo run this application:\n\n```bash\nnpm install\nnpm run start \n```\n\n# Building For Production\n\nTo build this application for production:\n\n```bash\nnpm run build\n```\n\n## Testing\n\nThis project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:\n\n```bash\nnpm run test\n```\n\n## Styling\n\nThis project uses CSS for styling.\n\n\n\n\n## Routing\nThis project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means that the routes are managed as files in `src/routes`.\n\n### Adding A Route\n\nTo add a new route to your application just add another a new file in the `./src/routes` directory.\n\nTanStack will automatically generate the content of the route file for you.\n\nNow that you have two routes you can use a `Link` component to navigate between them.\n\n### Adding Links\n\nTo use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.\n\n```tsx\nimport { Link } from \"@tanstack/react-router\";\n```\n\nThen anywhere in your JSX you can use it like so:\n\n```tsx\n<Link to=\"/about\">About</Link>\n```\n\nThis will create a link that will navigate to the `/about` route.\n\nMore information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).\n\n### Using A Layout\n\nIn the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes. The route content will appear in the JSX where you use the `<Outlet />` component.\n\nHere is an example layout that includes a header:\n\n```tsx\nimport { Outlet, createRootRoute } from '@tanstack/react-router'\nimport { TanStackRouterDevtools } from '@tanstack/react-router-devtools'\n\nimport { Link } from \"@tanstack/react-router\";\n\nexport const Route = createRootRoute({\n component: () => (\n <>\n <header>\n <nav>\n <Link to=\"/\">Home</Link>\n <Link to=\"/about\">About</Link>\n </nav>\n </header>\n <Outlet />\n <TanStackRouterDevtools />\n </>\n ),\n})\n```\n\nThe `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.\n\nMore information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).\n\n\n## Data Fetching\n\nThere 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.\n\nFor example:\n\n```tsx\nconst peopleRoute = createRoute({\n getParentRoute: () => rootRoute,\n path: \"/people\",\n loader: async () => {\n const response = await fetch(\"https://swapi.dev/api/people\");\n return response.json() as Promise<{\n results: {\n name: string;\n }[];\n }>;\n },\n component: () => {\n const data = peopleRoute.useLoaderData();\n return (\n <ul>\n {data.results.map((person) => (\n <li key={person.name}>{person.name}</li>\n ))}\n </ul>\n );\n },\n});\n```\n\nLoaders 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).\n\n### React-Query\n\nReact-Query is an excellent addition or alternative to route loading and integrating it into you application is a breeze.\n\nFirst add your dependencies:\n\n```bash\nnpm install @tanstack/react-query @tanstack/react-query-devtools\n```\n\nNext we'll need to create a query client and provider. We recommend putting those in `main.tsx`.\n\n```tsx\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\n\n// ...\n\nconst queryClient = new QueryClient();\n\n// ...\n\nif (!rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement);\n\n root.render(\n <QueryClientProvider client={queryClient}>\n <RouterProvider router={router} />\n </QueryClientProvider>\n );\n}\n```\n\nYou can also add TanStack Query Devtools to the root route (optional).\n\n```tsx\nimport { ReactQueryDevtools } from \"@tanstack/react-query-devtools\";\n\nconst rootRoute = createRootRoute({\n component: () => (\n <>\n <Outlet />\n <ReactQueryDevtools buttonPosition=\"top-right\" />\n <TanStackRouterDevtools />\n </>\n ),\n});\n```\n\nNow you can use `useQuery` to fetch your data.\n\n```tsx\nimport { useQuery } from \"@tanstack/react-query\";\n\nimport \"./App.css\";\n\nfunction App() {\n const { data } = useQuery({\n queryKey: [\"people\"],\n queryFn: () =>\n fetch(\"https://swapi.dev/api/people\")\n .then((res) => res.json())\n .then((data) => data.results as { name: string }[]),\n initialData: [],\n });\n\n return (\n <div>\n <ul>\n {data.map((person) => (\n <li key={person.name}>{person.name}</li>\n ))}\n </ul>\n </div>\n );\n}\n\nexport default App;\n```\n\nYou 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).\n\n## State Management\n\nAnother 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.\n\nFirst you need to add TanStack Store as a dependency:\n\n```bash\nnpm install @tanstack/store\n```\n\nNow let's create a simple counter in the `src/App.tsx` file as a demonstration.\n\n```tsx\nimport { useStore } from \"@tanstack/react-store\";\nimport { Store } from \"@tanstack/store\";\nimport \"./App.css\";\n\nconst countStore = new Store(0);\n\nfunction App() {\n const count = useStore(countStore);\n return (\n <div>\n <button onClick={() => countStore.setState((n) => n + 1)}>\n Increment - {count}\n </button>\n </div>\n );\n}\n\nexport default App;\n```\n\nOne 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.\n\nLet's check this out by doubling the count using derived state.\n\n```tsx\nimport { useStore } from \"@tanstack/react-store\";\nimport { Store, Derived } from \"@tanstack/store\";\nimport \"./App.css\";\n\nconst countStore = new Store(0);\n\nconst doubledStore = new Derived({\n fn: () => countStore.state * 2,\n deps: [countStore],\n});\ndoubledStore.mount();\n\nfunction App() {\n const count = useStore(countStore);\n const doubledCount = useStore(doubledStore);\n\n return (\n <div>\n <button onClick={() => countStore.setState((n) => n + 1)}>\n Increment - {count}\n </button>\n <div>Doubled - {doubledCount}</div>\n </div>\n );\n}\n\nexport default App;\n```\n\nWe 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.\n\nOnce 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.\n\nYou can find out everything you need to know on how to use TanStack Store in the [TanStack Store documentation](https://tanstack.com/store/latest).\n\n# Demo files\n\nFiles 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.\n\n# Learn More\n\nYou can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).\n",
|
|
15
|
+
"index.html": "<!DOCTYPE html>\n<html lang=\"en\">\n <head>\n <meta charset=\"UTF-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <link rel=\"icon\" href=\"/favicon.ico\" />\n <meta name=\"theme-color\" content=\"#000000\" />\n <meta\n name=\"description\"\n content=\"Web site created using create-tsrouter-app\"\n />\n <link rel=\"apple-touch-icon\" href=\"/logo192.png\" />\n <link rel=\"manifest\" href=\"/manifest.json\" />\n <title>Create TanStack App - TEST</title>\n </head>\n <body>\n <div id=\"app\"></div>\n <script type=\"module\" src=\"/src/main.tsx\"></script>\n </body>\n</html>\n",
|
|
16
|
+
"package.json": "{\n \"name\": \"TEST\",\n \"private\": true,\n \"type\": \"module\",\n \"scripts\": {\n \"dev\": \"vite --port 3000\",\n \"start\": \"vite --port 3000\",\n \"build\": \"vite build && tsc\",\n \"serve\": \"vite preview\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@tanstack/react-router\": \"^1.114.3\",\n \"@tanstack/react-router-devtools\": \"^1.114.3\",\n \"@tanstack/router-plugin\": \"^1.114.3\",\n \"react\": \"^19.0.0\",\n \"react-dom\": \"^19.0.0\"\n },\n \"devDependencies\": {\n \"@testing-library/dom\": \"^10.4.0\",\n \"@testing-library/react\": \"^16.2.0\",\n \"@types/react\": \"^19.0.8\",\n \"@types/react-dom\": \"^19.0.3\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^26.0.0\",\n \"typescript\": \"^5.7.2\",\n \"vite\": \"^6.1.0\",\n \"vitest\": \"^3.0.5\",\n \"web-vitals\": \"^4.2.4\"\n }\n}",
|
|
17
|
+
"tsconfig.json": "{\n \"include\": [\"**/*.ts\", \"**/*.tsx\"],\n \"compilerOptions\": {\n \"target\": \"ES2022\",\n \"jsx\": \"react-jsx\",\n \"module\": \"ESNext\",\n \"lib\": [\"ES2022\", \"DOM\", \"DOM.Iterable\"],\n \"types\": [\"vite/client\"],\n\n /* Bundler mode */\n \"moduleResolution\": \"bundler\",\n \"allowImportingTsExtensions\": true,\n \"verbatimModuleSyntax\": true,\n \"noEmit\": true,\n\n /* Linting */\n \"skipLibCheck\": true,\n \"strict\": true,\n \"noUnusedLocals\": true,\n \"noUnusedParameters\": true,\n \"noFallthroughCasesInSwitch\": true,\n \"noUncheckedSideEffectImports\": true,\n \"baseUrl\": \".\",\n \"paths\": {\n \"@/*\": [\"./src/*\"],\n }\n }\n}\n",
|
|
18
|
+
"vite.config.js": "import { defineConfig } from \"vite\";\nimport viteReact from \"@vitejs/plugin-react\";\nimport { TanStackRouterVite } from \"@tanstack/router-plugin/vite\";\nimport { resolve } from \"node:path\";\n\n// https://vitejs.dev/config/\nexport default defineConfig({\n plugins: [TanStackRouterVite({ autoCodeSplitting: true }), viteReact()],\n test: {\n globals: true,\n environment: \"jsdom\",\n },\n resolve: {\n alias: {\n '@': resolve(__dirname, './src'),\n },\n }\n});\n"
|
|
19
|
+
},
|
|
20
|
+
"commands": [
|
|
21
|
+
"git init",
|
|
22
|
+
"npm install"
|
|
23
|
+
]
|
|
24
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"files": {
|
|
3
|
+
".cta.json": "{\n \"addOns\": true,\n \"git\": true,\n \"mode\": \"file-router\",\n \"packageManager\": \"npm\",\n \"projectName\": \"TEST\",\n \"tailwind\": true,\n \"typescript\": true,\n \"variableValues\": {},\n \"version\": 1,\n \"framework\": \"react-cra\",\n \"existingAddOns\": [\n \"start\"\n ]\n}",
|
|
4
|
+
".gitignore": "node_modules\n.DS_Store\ndist\ndist-ssr\n*.local\n.output\n.vinxi\n",
|
|
5
|
+
"/.vscode/settings.json": "{\n \"files.watcherExclude\": {\n \"**/routeTree.gen.ts\": true\n },\n \"search.exclude\": {\n \"**/routeTree.gen.ts\": true\n },\n \"files.readonlyInclude\": {\n \"**/routeTree.gen.ts\": true\n }\n}\n",
|
|
6
|
+
"/public/manifest.json": "{\n \"short_name\": \"TanStack App\",\n \"name\": \"Create TanStack App Sample\",\n \"icons\": [\n {\n \"src\": \"favicon.ico\",\n \"sizes\": \"64x64 32x32 24x24 16x16\",\n \"type\": \"image/x-icon\"\n },\n {\n \"src\": \"logo192.png\",\n \"type\": \"image/png\",\n \"sizes\": \"192x192\"\n },\n {\n \"src\": \"logo512.png\",\n \"type\": \"image/png\",\n \"sizes\": \"512x512\"\n }\n ],\n \"start_url\": \".\",\n \"display\": \"standalone\",\n \"theme_color\": \"#000000\",\n \"background_color\": \"#ffffff\"\n}\n",
|
|
7
|
+
"/public/robots.txt": "# https://www.robotstxt.org/robotstxt.html\nUser-agent: *\nDisallow:\n",
|
|
8
|
+
"/src/api.ts": "import {\n createStartAPIHandler,\n defaultAPIFileRouteHandler,\n} from '@tanstack/react-start/api'\n\nexport default createStartAPIHandler(defaultAPIFileRouteHandler)\n",
|
|
9
|
+
"/src/client.tsx": "import { hydrateRoot } from 'react-dom/client'\nimport { StartClient } from '@tanstack/react-start'\n\nimport { createRouter } from './router'\n\nconst router = createRouter()\n\nhydrateRoot(document, <StartClient router={router} />)\n",
|
|
10
|
+
"/src/components/Header.tsx": "import { Link } from '@tanstack/react-router'\n\nexport default function Header() {\n return (\n <header className=\"p-2 flex gap-2 bg-white text-black justify-between\">\n <nav className=\"flex flex-row\">\n <div className=\"px-2 font-bold\">\n <Link to=\"/\">Home</Link>\n </div>\n\n <div className=\"px-2 font-bold\">\n <Link to=\"/demo/start/server-funcs\">Start - Server Functions</Link>\n </div>\n\n <div className=\"px-2 font-bold\">\n <Link to=\"/demo/start/api-request\">Start - API Request</Link>\n </div>\n </nav>\n </header>\n )\n}\n",
|
|
11
|
+
"/src/router.tsx": "import { createRouter as createTanstackRouter } from '@tanstack/react-router'\n\n// Import the generated route tree\nimport { routeTree } from './routeTree.gen'\n\nimport './styles.css'\n\n// Create a new router instance\nexport const createRouter = () => {\n const router = createTanstackRouter({\n routeTree,\n scrollRestoration: true,\n defaultPreloadStaleTime: 0,\n })\n\n return router\n}\n\n// Register the router instance for type safety\ndeclare module '@tanstack/react-router' {\n interface Register {\n router: ReturnType<typeof createRouter>\n }\n}\n",
|
|
12
|
+
"/src/routes/__root.tsx": "import {\n Outlet,\n HeadContent,\n Scripts,\n createRootRoute,\n} from '@tanstack/react-router'\nimport { TanStackRouterDevtools } from '@tanstack/react-router-devtools'\n\nimport Header from '../components/Header'\n\nimport appCss from '../styles.css?url'\n\nexport const Route = createRootRoute({\n head: () => ({\n meta: [\n {\n charSet: 'utf-8',\n },\n {\n name: 'viewport',\n content: 'width=device-width, initial-scale=1',\n },\n {\n title: 'TanStack Start Starter',\n },\n ],\n links: [\n {\n rel: 'stylesheet',\n href: appCss,\n },\n ],\n }),\n\n component: () => (\n <RootDocument>\n <Header />\n\n <Outlet />\n <TanStackRouterDevtools />\n </RootDocument>\n ),\n})\n\nfunction RootDocument({ children }: { children: React.ReactNode }) {\n return (\n <html lang=\"en\">\n <head>\n <HeadContent />\n </head>\n <body>\n {children}\n <Scripts />\n </body>\n </html>\n )\n}\n",
|
|
13
|
+
"/src/routes/api.demo-names.ts": "import { createAPIFileRoute } from '@tanstack/react-start/api'\n\nexport const APIRoute = createAPIFileRoute('/demo/start/api/names')({\n GET: async ({ request }) => {\n return new Response(JSON.stringify(['Alice', 'Bob', 'Charlie']), {\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n },\n})\n",
|
|
14
|
+
"/src/routes/demo.start.api-request.tsx": "import { useEffect, useState } from 'react'\n\nimport { createFileRoute } from '@tanstack/react-router'\n\nfunction getNames() {\n return fetch('/api/demo-names').then((res) => res.json())\n}\n\nexport const Route = createFileRoute('/demo/start/api-request')({\n component: Home,\n})\n\nfunction Home() {\n const [names, setNames] = useState<Array<string>>([])\n useEffect(() => {\n getNames().then(setNames)\n }, [])\n\n return (\n <div className=\"p-4\">\n <div>{names.join(', ')}</div>\n </div>\n )\n}\n",
|
|
15
|
+
"/src/routes/demo.start.server-funcs.tsx": "import * as fs from 'node:fs'\nimport { createFileRoute, useRouter } from '@tanstack/react-router'\nimport { createServerFn } from '@tanstack/react-start'\n\nconst filePath = 'count.txt'\n\nasync function readCount() {\n return parseInt(\n await fs.promises.readFile(filePath, 'utf-8').catch(() => '0'),\n )\n}\n\nconst getCount = createServerFn({\n method: 'GET',\n}).handler(() => {\n return readCount()\n})\n\nconst updateCount = createServerFn({ method: 'POST' })\n .validator((d: number) => d)\n .handler(async ({ data }) => {\n const count = await readCount()\n await fs.promises.writeFile(filePath, `${count + data}`)\n })\n\nexport const Route = createFileRoute('/demo/start/server-funcs')({\n component: Home,\n loader: async () => await getCount(),\n})\n\nfunction Home() {\n const router = useRouter()\n const state = Route.useLoaderData()\n\n return (\n <div className=\"p-4\">\n <button\n type=\"button\"\n onClick={() => {\n updateCount({ data: 1 }).then(() => {\n router.invalidate()\n })\n }}\n className=\"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded\"\n >\n Add 1 to {state}?\n </button>\n </div>\n )\n}\n",
|
|
16
|
+
"/src/routes/index.tsx": "import { createFileRoute } from '@tanstack/react-router'\nimport logo from '../logo.svg'\n\nexport const Route = createFileRoute('/')({\n component: App,\n})\n\nfunction App() {\n return (\n <div className=\"text-center\">\n <header className=\"min-h-screen flex flex-col items-center justify-center bg-[#282c34] text-white text-[calc(10px+2vmin)]\">\n <img\n src={logo}\n className=\"h-[40vmin] pointer-events-none animate-[spin_20s_linear_infinite]\"\n alt=\"logo\"\n />\n <p>\n Edit <code>src/routes/index.tsx</code> and save to reload.\n </p>\n <a\n className=\"text-[#61dafb] hover:underline\"\n href=\"https://reactjs.org\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn React\n </a>\n <a\n className=\"text-[#61dafb] hover:underline\"\n href=\"https://tanstack.com\"\n target=\"_blank\"\n rel=\"noopener noreferrer\"\n >\n Learn TanStack\n </a>\n </header>\n </div>\n )\n}\n",
|
|
17
|
+
"/src/ssr.tsx": "import {\n createStartHandler,\n defaultStreamHandler,\n} from '@tanstack/react-start/server'\nimport { getRouterManifest } from '@tanstack/react-start/router-manifest'\n\nimport { createRouter } from './router'\n\nlet streamHandler = defaultStreamHandler\n\nexport default createStartHandler({\n createRouter,\n getRouterManifest,\n})(streamHandler)\n",
|
|
18
|
+
"/src/styles.css": "@import \"tailwindcss\";\n\nbody {\n @apply m-0;\n font-family: -apple-system, BlinkMacSystemFont, \"Segoe UI\", \"Roboto\", \"Oxygen\",\n \"Ubuntu\", \"Cantarell\", \"Fira Sans\", \"Droid Sans\", \"Helvetica Neue\",\n sans-serif;\n -webkit-font-smoothing: antialiased;\n -moz-osx-font-smoothing: grayscale;\n}\n\ncode {\n font-family: source-code-pro, Menlo, Monaco, Consolas, \"Courier New\",\n monospace;\n}\n",
|
|
19
|
+
"README.md": "Welcome to your new TanStack app! \n\n# Getting Started\n\nTo run this application:\n\n```bash\nnpm install\nnpm run start \n```\n\n# Building For Production\n\nTo build this application for production:\n\n```bash\nnpm run build\n```\n\n## Testing\n\nThis project uses [Vitest](https://vitest.dev/) for testing. You can run the tests with:\n\n```bash\nnpm run test\n```\n\n## Styling\n\nThis project uses [Tailwind CSS](https://tailwindcss.com/) for styling.\n\n\n\n\n## Routing\nThis project uses [TanStack Router](https://tanstack.com/router). The initial setup is a file based router. Which means that the routes are managed as files in `src/routes`.\n\n### Adding A Route\n\nTo add a new route to your application just add another a new file in the `./src/routes` directory.\n\nTanStack will automatically generate the content of the route file for you.\n\nNow that you have two routes you can use a `Link` component to navigate between them.\n\n### Adding Links\n\nTo use SPA (Single Page Application) navigation you will need to import the `Link` component from `@tanstack/react-router`.\n\n```tsx\nimport { Link } from \"@tanstack/react-router\";\n```\n\nThen anywhere in your JSX you can use it like so:\n\n```tsx\n<Link to=\"/about\">About</Link>\n```\n\nThis will create a link that will navigate to the `/about` route.\n\nMore information on the `Link` component can be found in the [Link documentation](https://tanstack.com/router/v1/docs/framework/react/api/router/linkComponent).\n\n### Using A Layout\n\nIn the File Based Routing setup the layout is located in `src/routes/__root.tsx`. Anything you add to the root route will appear in all the routes. The route content will appear in the JSX where you use the `<Outlet />` component.\n\nHere is an example layout that includes a header:\n\n```tsx\nimport { Outlet, createRootRoute } from '@tanstack/react-router'\nimport { TanStackRouterDevtools } from '@tanstack/react-router-devtools'\n\nimport { Link } from \"@tanstack/react-router\";\n\nexport const Route = createRootRoute({\n component: () => (\n <>\n <header>\n <nav>\n <Link to=\"/\">Home</Link>\n <Link to=\"/about\">About</Link>\n </nav>\n </header>\n <Outlet />\n <TanStackRouterDevtools />\n </>\n ),\n})\n```\n\nThe `<TanStackRouterDevtools />` component is not required so you can remove it if you don't want it in your layout.\n\nMore information on layouts can be found in the [Layouts documentation](https://tanstack.com/router/latest/docs/framework/react/guide/routing-concepts#layouts).\n\n\n## Data Fetching\n\nThere 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.\n\nFor example:\n\n```tsx\nconst peopleRoute = createRoute({\n getParentRoute: () => rootRoute,\n path: \"/people\",\n loader: async () => {\n const response = await fetch(\"https://swapi.dev/api/people\");\n return response.json() as Promise<{\n results: {\n name: string;\n }[];\n }>;\n },\n component: () => {\n const data = peopleRoute.useLoaderData();\n return (\n <ul>\n {data.results.map((person) => (\n <li key={person.name}>{person.name}</li>\n ))}\n </ul>\n );\n },\n});\n```\n\nLoaders 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).\n\n### React-Query\n\nReact-Query is an excellent addition or alternative to route loading and integrating it into you application is a breeze.\n\nFirst add your dependencies:\n\n```bash\nnpm install @tanstack/react-query @tanstack/react-query-devtools\n```\n\nNext we'll need to create a query client and provider. We recommend putting those in `main.tsx`.\n\n```tsx\nimport { QueryClient, QueryClientProvider } from \"@tanstack/react-query\";\n\n// ...\n\nconst queryClient = new QueryClient();\n\n// ...\n\nif (!rootElement.innerHTML) {\n const root = ReactDOM.createRoot(rootElement);\n\n root.render(\n <QueryClientProvider client={queryClient}>\n <RouterProvider router={router} />\n </QueryClientProvider>\n );\n}\n```\n\nYou can also add TanStack Query Devtools to the root route (optional).\n\n```tsx\nimport { ReactQueryDevtools } from \"@tanstack/react-query-devtools\";\n\nconst rootRoute = createRootRoute({\n component: () => (\n <>\n <Outlet />\n <ReactQueryDevtools buttonPosition=\"top-right\" />\n <TanStackRouterDevtools />\n </>\n ),\n});\n```\n\nNow you can use `useQuery` to fetch your data.\n\n```tsx\nimport { useQuery } from \"@tanstack/react-query\";\n\nimport \"./App.css\";\n\nfunction App() {\n const { data } = useQuery({\n queryKey: [\"people\"],\n queryFn: () =>\n fetch(\"https://swapi.dev/api/people\")\n .then((res) => res.json())\n .then((data) => data.results as { name: string }[]),\n initialData: [],\n });\n\n return (\n <div>\n <ul>\n {data.map((person) => (\n <li key={person.name}>{person.name}</li>\n ))}\n </ul>\n </div>\n );\n}\n\nexport default App;\n```\n\nYou 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).\n\n## State Management\n\nAnother 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.\n\nFirst you need to add TanStack Store as a dependency:\n\n```bash\nnpm install @tanstack/store\n```\n\nNow let's create a simple counter in the `src/App.tsx` file as a demonstration.\n\n```tsx\nimport { useStore } from \"@tanstack/react-store\";\nimport { Store } from \"@tanstack/store\";\nimport \"./App.css\";\n\nconst countStore = new Store(0);\n\nfunction App() {\n const count = useStore(countStore);\n return (\n <div>\n <button onClick={() => countStore.setState((n) => n + 1)}>\n Increment - {count}\n </button>\n </div>\n );\n}\n\nexport default App;\n```\n\nOne 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.\n\nLet's check this out by doubling the count using derived state.\n\n```tsx\nimport { useStore } from \"@tanstack/react-store\";\nimport { Store, Derived } from \"@tanstack/store\";\nimport \"./App.css\";\n\nconst countStore = new Store(0);\n\nconst doubledStore = new Derived({\n fn: () => countStore.state * 2,\n deps: [countStore],\n});\ndoubledStore.mount();\n\nfunction App() {\n const count = useStore(countStore);\n const doubledCount = useStore(doubledStore);\n\n return (\n <div>\n <button onClick={() => countStore.setState((n) => n + 1)}>\n Increment - {count}\n </button>\n <div>Doubled - {doubledCount}</div>\n </div>\n );\n}\n\nexport default App;\n```\n\nWe 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.\n\nOnce 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.\n\nYou can find out everything you need to know on how to use TanStack Store in the [TanStack Store documentation](https://tanstack.com/store/latest).\n\n# Demo files\n\nFiles 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.\n\n# Learn More\n\nYou can learn more about all of the offerings from TanStack in the [TanStack documentation](https://tanstack.com).\n",
|
|
20
|
+
"app.config.ts": "import { defineConfig } from '@tanstack/react-start/config'\nimport viteTsConfigPaths from 'vite-tsconfig-paths'\nimport tailwindcss from '@tailwindcss/vite'\n\nconst config = defineConfig({\n tsr: {\n appDirectory: 'src',\n },\n vite: {\n plugins: [\n // this is the plugin that enables path aliases\n viteTsConfigPaths({\n projects: ['./tsconfig.json'],\n }),\n tailwindcss(),\n ],\n },\n})\n\nexport default config\n",
|
|
21
|
+
"package.json": "{\n \"name\": \"TEST\",\n \"private\": true,\n \"type\": \"module\",\n \"scripts\": {\n \"dev\": \"vinxi dev\",\n \"start\": \"vinxi start\",\n \"build\": \"vinxi build\",\n \"serve\": \"vite preview\",\n \"test\": \"vitest run\"\n },\n \"dependencies\": {\n \"@tailwindcss/vite\": \"^4.0.6\",\n \"@tanstack/react-router\": \"^1.114.3\",\n \"@tanstack/react-router-devtools\": \"^1.114.3\",\n \"@tanstack/react-router-with-query\": \"^1.114.3\",\n \"@tanstack/react-start\": \"^1.114.3\",\n \"@tanstack/router-plugin\": \"^1.114.3\",\n \"react\": \"^19.0.0\",\n \"react-dom\": \"^19.0.0\",\n \"tailwindcss\": \"^4.0.6\",\n \"vinxi\": \"^0.5.3\",\n \"vite-tsconfig-paths\": \"^5.1.4\"\n },\n \"devDependencies\": {\n \"@testing-library/dom\": \"^10.4.0\",\n \"@testing-library/react\": \"^16.2.0\",\n \"@types/react\": \"^19.0.8\",\n \"@types/react-dom\": \"^19.0.3\",\n \"@vitejs/plugin-react\": \"^4.3.4\",\n \"jsdom\": \"^26.0.0\",\n \"typescript\": \"^5.7.2\",\n \"vite\": \"^6.1.0\",\n \"vitest\": \"^3.0.5\",\n \"web-vitals\": \"^4.2.4\"\n }\n}",
|
|
22
|
+
"tsconfig.json": "{\n \"include\": [\"**/*.ts\", \"**/*.tsx\"],\n \"compilerOptions\": {\n \"target\": \"ES2022\",\n \"jsx\": \"react-jsx\",\n \"module\": \"ESNext\",\n \"lib\": [\"ES2022\", \"DOM\", \"DOM.Iterable\"],\n \"types\": [\"vite/client\"],\n\n /* Bundler mode */\n \"moduleResolution\": \"bundler\",\n \"allowImportingTsExtensions\": true,\n \"verbatimModuleSyntax\": true,\n \"noEmit\": true,\n\n /* Linting */\n \"skipLibCheck\": true,\n \"strict\": true,\n \"noUnusedLocals\": true,\n \"noUnusedParameters\": true,\n \"noFallthroughCasesInSwitch\": true,\n \"noUncheckedSideEffectImports\": true,\n \"baseUrl\": \".\",\n \"paths\": {\n \"@/*\": [\"./src/*\"],\n }\n }\n}\n"
|
|
23
|
+
},
|
|
24
|
+
"commands": [
|
|
25
|
+
"git init",
|
|
26
|
+
"npm install"
|
|
27
|
+
]
|
|
28
|
+
}
|