-
I've a component that looks like this "use client";
import { useMachine } from "@xstate/react";
import { setup } from "xstate";
function Component() {
const [state, dispatch] = useMachine(
setup({}).createMachine({
initial: "idle",
states: {
idle: {},
},
})
);
return <div>Hello world!</div>;
} If I try to render that in my NextJS application then I get
What am I doing wrong here? |
Beta Was this translation helpful? Give feedback.
Answered by
Andarist
May 2, 2024
Replies: 1 comment 2 replies
-
You create new machines on each render. Try this: "use client";
import { useMachine } from "@xstate/react";
import { setup } from "xstate";
const machine = setup({}).createMachine({
initial: "idle",
states: {
idle: {},
},
})
function Component() {
const [state, dispatch] = useMachine(machine);
return <div>Hello world!</div>;
} |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
NixBiks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You create new machines on each render. Try this: