forked from denoland/fresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsxConditional.tsx
More file actions
32 lines (28 loc) · 823 Bytes
/
JsxConditional.tsx
File metadata and controls
32 lines (28 loc) · 823 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import { useSignal } from "@preact/signals";
import { useEffect } from "preact/hooks";
import type { ComponentChildren } from "preact";
export interface JsxConditionalProps {
jsx?: ComponentChildren;
children?: ComponentChildren;
}
export function JsxConditional(props: JsxConditionalProps) {
const active = useSignal(false);
const sig = useSignal(0);
useEffect(() => {
active.value = true;
}, []);
return (
<div class={active.value ? "ready" : ""}>
<p class="cond-output">{sig}</p>
<button
type="button"
class="cond-update"
onClick={() => sig.value = sig.peek() + 1}
>
update
</button>
<div class="jsx">{active.value ? props.jsx : null}</div>
<div class="children">{active.value ? props.children : null}</div>
</div>
);
}