Public
Script
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
33
34
35
36
37
/** @jsxImportSource https://esm.sh/react */
import React, { useState } from "https://esm.sh/react";
type Props = {
initialCount?: Number;
};
export default function Counter(props: Props) {
const [count, setCount] = useState(props.initialCount || 0);
const increment = () => {
setCount(count + 1);
};
const decrement = () => {
setCount(count - 1);
};
return (
<div>
<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-l"
onClick={decrement}
>
-
</button>
<span className="bg-white border border-blue-500 py-2 px-4">{count}</span>
<button
className="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded-r"
onClick={increment}
>
+
</button>
</div>
);
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
Comments
Nobody has commented on this val yet: be the first!
February 29, 2024