diff --git a/docs/concepts/islands.md b/docs/concepts/islands.md
index e196e5fd..7c571bea 100644
--- a/docs/concepts/islands.md
+++ b/docs/concepts/islands.md
@@ -14,15 +14,14 @@ island. The file must have a default export that is a regular Preact component.
```tsx
// islands/MyIsland.tsx
-import { useState } from "preact/hooks";
+import type { Signal } from "@preact/signals";
export default function MyIsland() {
- const [count, setCount] = useState(0);
+ const count = useSignal(0);
return (
- Counter is at {count}.{" "}
-
+ Counter is at {count}.
);
}
diff --git a/docs/getting-started/adding-interactivity.md b/docs/getting-started/adding-interactivity.md
index 981e1c7e..767ec13e 100644
--- a/docs/getting-started/adding-interactivity.md
+++ b/docs/getting-started/adding-interactivity.md
@@ -31,7 +31,8 @@ Here is an example of an island component that counts down to a specific time.
```tsx
// islands/Countdown.tsx
-import { useEffect, useState } from "preact/hooks";
+import { useSignal } from "@preact/signals";
+import { useEffect } from "preact/hooks";
const timeFmt = new Intl.RelativeTimeFormat("en-US");
@@ -39,18 +40,16 @@ const timeFmt = new Intl.RelativeTimeFormat("en-US");
// props to island components need to be JSON (de)serializable.
export default function Countdown(props: { target: string }) {
const target = new Date(props.target);
- const [now, setNow] = useState(new Date());
+ const now = useSignal(new Date());
// Set up an interval to update the `now` date every second with the current
// date as long as the component is mounted.
useEffect(() => {
const timer = setInterval(() => {
- setNow((now) => {
- if (now > target) {
- clearInterval(timer);
- }
- return new Date();
- });
+ if (now.value > target) {
+ clearInterval(timer);
+ }
+ now.value = new Date();
}, 1000);
return () => clearInterval(timer);
}, [props.target]);
diff --git a/init.ts b/init.ts
index 1d892653..2c382e27 100644
--- a/init.ts
+++ b/init.ts
@@ -112,9 +112,11 @@ await Deno.writeTextFile(
);
const ROUTES_INDEX_TSX = `import { Head } from "$fresh/runtime.ts";
+import { useSignal } from "@preact/signals";
import Counter from "../islands/Counter.tsx";
export default function Home() {
+ const count = useSignal(3);
return (
<>
@@ -132,7 +134,7 @@ export default function Home() {
Welcome to \`fresh\`. Try updating this message in the
./routes/index.tsx file, and refresh.
-
+
>
);
@@ -164,20 +166,21 @@ await Deno.writeTextFile(
COMPONENTS_BUTTON_TSX,
);
-const ISLANDS_COUNTER_TSX = `import { useState } from "preact/hooks";
+const ISLANDS_COUNTER_TSX = `import type { Signal } from "@preact/signals";
import { Button } from "../components/Button.tsx";
interface CounterProps {
- start: number;
+ count: Signal;
}
export default function Counter(props: CounterProps) {
- const [count, setCount] = useState(props.start);
return (