Skip to content
Source
Sign inSign up
TanStack/router
Open History to see the last commit

shared-runtime.tsx

50 lines1.2 KB

1import { createFileRoute } from '@tanstack/react-router'
2​
3const Count = { Initial: 0 }
4​
5const Labels = { component: 'count' }
6​
7const seed = createSeed()
8const { state, increment } = createState(seed)
9const label = createComponentLabel()
10console.log('shared-runtime:reference')
11​
12export const Route = createFileRoute('/shared-runtime')({
13 beforeLoad: () => state,
14 loader: () => {
15 increment()
16 return state
17 },
18 component: () => {
19 if (state.count === 3) {
20 throw new Error('route source-map contract')
21 }
22 return `${label}:${state.count}`
23 },
24})
25​
26function createSeed() {
27 console.log('shared-runtime:seed')
28 return { count: Count.Initial, label: Labels.component }
30​
31function createState(initialState: { count: number }): {
32 state: { count: number }
33 increment: () => number
35function createState(initialState: { count: number }) {
36 console.log('shared-runtime:state')
37 return {
38 state: initialState,
39 increment: () => initialState.count++,
40 }
42​
43function createComponentLabel() {
44 console.log('shared-runtime:component')
45 return Labels.component
47​
48export { state as firstState, state as secondState, state as 'odd-name' }
49​
50export default createSeed