ziex/test/data/component/optional_error.zx
2026-01-08 15:13:27 +06:00

19 lines
577 B
Zig

/// Test: Components with error union of optional return type (!?Component)
pub fn Page(allocator: zx.Allocator) zx.Component {
return (
<main @allocator={allocator}>
<MaybeContent show={true} />
<MaybeContent show={false} />
</main>
);
}
/// Error union of optional - !?Component
const MaybeProps = struct { show: bool };
pub fn MaybeContent(ctx: *zx.ComponentCtx(MaybeProps)) !?zx.Component {
if (!ctx.props.show) return null;
return (<div @allocator={ctx.allocator}>Shown Content</div>);
}
const zx = @import("zx");