statelyai / xstate

Actor-based state management & orchestration for complex app logic.
https://stately.ai/docs
MIT License
26.51k stars 1.22k forks source link

Bug: _xstate_react__WEBPACK_IMPORTED_MODULE_1__.useInterpret is not a function #4927

Closed gls-manifold closed 1 month ago

gls-manifold commented 1 month ago

XState version

XState version 5

Description

I try to use this hook link as in the example, but I get an error: _xstate_react__WEBPACK_IMPORTED_MODULE_1__.useInterpret is not a function

"xstate": "^5.8.0", "@xstate/react": "^4.1.1",

Expected result

Working hook

Actual result

_xstate_react__WEBPACK_IMPORTED_MODULE_1__.useInterpret is not a function

Reproduction

xstate/react

Additional context

No response

davidkpiano commented 1 month ago

This is as expected; it has been deprecated. Please see here: https://stately.ai/docs/migration#useinterpret-is-now-useactorref


useInterpret() is now useActorRef()

Breaking change

The useInterpret() hook, which is used to return an actorRef ("service" in XState v4), is renamed to useActorRef().

// ✅
import { useActorRef } from '@xstate/react';

const actorRef = useActorRef(machine); // or any other logic
// ❌ DEPRECATED
import { useInterpret } from '@xstate/react';

const service = useInterpret(machine);