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

condition.ts

20 lines534 Bytes

1import type { HydrationStrategy } from './types'
2​
3const conditionType = 'condition'
4​
5export type HydrationCondition = boolean | (() => boolean)
6​
7/* @__NO_SIDE_EFFECTS__ */
8export function condition(
9 condition: HydrationCondition,
10): HydrationStrategy<typeof conditionType, false> {
11 return {
12 _t: conditionType,
13 _d: () => !(typeof condition === 'function' ? condition() : condition),
14 _s: ({ gate }) => {
15 if (typeof condition === 'function' ? condition() : condition) {
16 gate!.resolve()
17 }
18 },
19 }