Open History to see the last commit
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 }
20}