Skip to content

Infinite loop in NextJS client component no matter what I do #4877

Answered by Andarist
NixBiks asked this question in Q&A
Discussion options

You must be logged in to vote

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>;
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@NixBiks
Comment options

@Andarist
Comment options

Answer selected by NixBiks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants