refactor: replace useState() with useSignal() (#1234)

This commit is contained in:
Asher Gomez
2023-06-02 06:43:01 +10:00
committed by GitHub
parent 7b35cb07d4
commit 8fa4141e06
15 changed files with 120 additions and 112 deletions
+4 -5
View File
@@ -1,19 +1,18 @@
import { useState } from "preact/hooks";
import type { Signal } from "@preact/signals";
import { IS_BROWSER } from "$fresh/runtime.ts";
interface CounterProps {
start: number;
count: Signal<number>;
id: string;
}
export default function Counter(props: CounterProps) {
const [count, setCount] = useState(props.start);
return (
<div id={props.id}>
<p>{count}</p>
<p>{props.count}</p>
<button
id={`b-${props.id}`}
onClick={() => setCount(count + 1)}
onClick={() => props.count.value += 1}
disabled={!IS_BROWSER}
>
+1