feat: support passing signals as island props (#757)
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.
This commit is contained in:
@@ -1,19 +1,18 @@
|
||||
import { useState } from "preact/hooks";
|
||||
import { Signal } from "@preact/signals";
|
||||
import { IS_BROWSER } from "$fresh/runtime.ts";
|
||||
|
||||
interface CounterProps {
|
||||
start: number;
|
||||
count: Signal<number>;
|
||||
}
|
||||
|
||||
export default function Counter(props: CounterProps) {
|
||||
const [count, setCount] = useState(props.start);
|
||||
export default function Counter({ count }: CounterProps) {
|
||||
return (
|
||||
<div>
|
||||
<p>{count}</p>
|
||||
<button onClick={() => setCount(count - 1)} disabled={!IS_BROWSER}>
|
||||
<button onClick={() => count.value -= 1} disabled={!IS_BROWSER}>
|
||||
-1
|
||||
</button>
|
||||
<button onClick={() => setCount(count + 1)} disabled={!IS_BROWSER}>
|
||||
<button onClick={() => count.value += 1} disabled={!IS_BROWSER}>
|
||||
+1
|
||||
</button>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user