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

conditionalCssServerComponent.tsx

22 lines699 Bytes

1import { createServerFn } from '@tanstack/react-start'
2import { renderServerComponent } from '@tanstack/react-start/rsc'
3import { ConditionalOrangePanel } from './ConditionalOrangePanel'
4import { ConditionalVioletPanel } from './ConditionalVioletPanel'
5​
6export const getConditionalCssServerComponent = createServerFn({
7 method: 'GET',
8})
9 .validator((data: { branch?: 'orange' | 'violet' }) => data)
10 .handler(async ({ data }) => {
11 const branch = data.branch === 'violet' ? 'violet' : 'orange'
12​
13 return renderServerComponent(
14 <>
15 {branch === 'violet' ? (
16 <ConditionalVioletPanel />
17 ) : (
18 <ConditionalOrangePanel />
19 )}
20 </>,
21 )
22 })