forked from denoland/fresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsxIsland.tsx
More file actions
32 lines (29 loc) · 879 Bytes
/
JsxIsland.tsx
File metadata and controls
32 lines (29 loc) · 879 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, isValidElement } from "preact";
export interface JsxIslandProps {
jsx?: ComponentChildren;
children?: ComponentChildren;
}
export function JsxIsland(props: JsxIslandProps) {
const active = useSignal(false);
const sig = useSignal(0);
useEffect(() => {
active.value = true;
}, []);
return (
<div class={active.value ? "ready" : ""}>
<p class="output">{sig}</p>
<button
type="button"
class="update"
onClick={() => sig.value = sig.peek() + 1}
>
update
</button>
<div class="jsx">{props.jsx}</div>
<div class="children">{props.children}</div>
<pre>{JSON.stringify({jsx: isValidElement(props.jsx), children: isValidElement(props.children)})}</pre>
</div>
);
}