This commit adds support for passing signals to islands in component props. This is useful for passing around mutable state between islands. The signal's value needs to be serializable for this to work.
21 lines
459 B
TypeScript
21 lines
459 B
TypeScript
import { Signal } from "@preact/signals";
|
|
import { IS_BROWSER } from "$fresh/runtime.ts";
|
|
|
|
interface CounterProps {
|
|
count: Signal<number>;
|
|
}
|
|
|
|
export default function Counter({ count }: CounterProps) {
|
|
return (
|
|
<div>
|
|
<p>{count}</p>
|
|
<button onClick={() => count.value -= 1} disabled={!IS_BROWSER}>
|
|
-1
|
|
</button>
|
|
<button onClick={() => count.value += 1} disabled={!IS_BROWSER}>
|
|
+1
|
|
</button>
|
|
</div>
|
|
);
|
|
}
|