Skip to content

Commit dc77051

Browse files
committed
Store demo page update
1 parent 8c8dd83 commit dc77051

File tree

5 files changed

+87
-85
lines changed

5 files changed

+87
-85
lines changed
Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
1-
import { Store } from '@tanstack/store'
1+
import { Derived, Store } from '@tanstack/store'
22

33
export const store = new Store({
4-
count: 0,
4+
firstName: 'Jane',
5+
lastName: 'Smith',
56
})
7+
8+
export const fullName = new Derived({
9+
fn: () => `${store.state.firstName} ${store.state.lastName}`,
10+
deps: [store],
11+
})
12+
13+
fullName.mount()

templates/react/add-on/store/assets/src/routes/demo.store.page1.tsx.ejs

Lines changed: 0 additions & 38 deletions
This file was deleted.

templates/react/add-on/store/assets/src/routes/demo.store.page2.tsx.ejs

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import { <% if (fileRouter) { %>createFileRoute<% } else { %>createRoute<% } %> } from '@tanstack/react-router'
2+
import { useStore } from '@tanstack/react-store'
3+
4+
import { fullName, store } from '../lib/demo-store'
5+
<% if (codeRouter) { %>
6+
import type { RootRoute } from '@tanstack/react-router'
7+
<% } else { %>
8+
export const Route = createFileRoute('/demo/store')({
9+
component: DemoStore,
10+
})
11+
<% } %>
12+
13+
function FirstName() {
14+
const firstName = useStore(store, (state) => state.firstName)
15+
return (
16+
<input
17+
type="text"
18+
value={firstName}
19+
onChange={(e) =>
20+
store.setState((state) => ({ ...state, firstName: e.target.value }))
21+
}
22+
className="bg-white/10 rounded-lg px-4 py-2 outline-none border border-white/20 hover:border-white/40 focus:border-white/60 transition-colors duration-200 placeholder-white/40"
23+
/>
24+
)
25+
}
26+
27+
function LastName() {
28+
const lastName = useStore(store, (state) => state.lastName)
29+
return (
30+
<input
31+
type="text"
32+
value={lastName}
33+
onChange={(e) =>
34+
store.setState((state) => ({ ...state, lastName: e.target.value }))
35+
}
36+
className="bg-white/10 rounded-lg px-4 py-2 outline-none border border-white/20 hover:border-white/40 focus:border-white/60 transition-colors duration-200 placeholder-white/40"
37+
/>
38+
)
39+
}
40+
41+
function FullName() {
42+
const fName = useStore(fullName)
43+
return (
44+
<div className="bg-white/10 rounded-lg px-4 py-2 outline-none ">
45+
{fName}
46+
</div>
47+
)
48+
}
49+
50+
function DemoStore() {
51+
return (
52+
<div
53+
className="min-h-[calc(100vh-32px)] text-white p-8 flex items-center justify-center w-full h-full"
54+
style={{
55+
backgroundImage:
56+
'radial-gradient(50% 50% at 80% 80%, #f4a460 0%, #8b4513 70%, #1a0f0a 100%)',
57+
}}
58+
>
59+
<div className="bg-white/10 backdrop-blur-lg rounded-xl p-8 shadow-lg flex flex-col gap-4 text-3xl min-w-1/2">
60+
<h1 className="text-4xl font-bold mb-5">Store Example</h1>
61+
<FirstName />
62+
<LastName />
63+
<FullName />
64+
</div>
65+
</div>
66+
)
67+
}
68+
69+
<% if (codeRouter) { %>
70+
export default (parentRoute: RootRoute) => createRoute({
71+
path: '/demo/store',
72+
component: DemoStore,
73+
getParentRoute: () => parentRoute,
74+
})
75+
<% } %>

templates/react/add-on/store/info.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,8 @@
66
"templates": ["file-router", "code-router"],
77
"routes": [
88
{
9-
"url": "/demo/store/page1",
10-
"name": "Store Pg 1"
11-
},
12-
{
13-
"url": "/demo/store/page2",
14-
"name": "Store Pg 2"
9+
"url": "/demo/store",
10+
"name": "Store"
1511
}
1612
]
1713
}

0 commit comments

Comments
 (0)