๐Ÿ“ฆ vercel / next.js

๐Ÿ“„ Counter.tsx ยท 18 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18"use client";
import { useMachine } from "@xstate/react";
import { counterMachine } from "../_machines/counter";

export default function Counter({ counter = {} }) {
  const [state, send] = useMachine(counterMachine);
  return (
    <section>
      <h2>
        Count: <span>{state.context.count}</span>
      </h2>
      <button onClick={() => send({ type: "DEC" })}>-1</button>
      <button onClick={() => send({ type: "INC" })}>+1</button>
      <button onClick={() => send({ type: "RESET" })}>Reset</button>
    </section>
  );
}