Major Changes
-
#3947
5fa3a0c74
Thanks @davidkpiano! - Removed the ability to pass a factory function as argument touseMachine
anduseInterpret
. -
#4006
42df9a536
Thanks @davidkpiano! -useActorRef
is introduced, which returns anActorRef
from actor logic:const actorRef = useActorRef(machine, { ... }); const anotherActorRef = useActorRef(fromPromise(...));
is deprecated in favor ofuseMachine
useActor
, which works with machines and any other kind of logic-const [state, send] = useMachine(machine); +const [state, send] = useActor(machine); const [state, send] = useActor(fromTransition(...));
is removed in favor ofuseSpawn
useActorRef
-const actorRef = useSpawn(machine); +const actorRef = useActorRef(machine); The previous use of `useActor(actorRef)` is now replaced with just using the `actorRef` directly, and with `useSelector`: ```diff -const [state, send] = useActor(actorRef); +const state = useSelector(actorRef, s => s); // actorRef.send(...)
-
#4006
42df9a536
Thanks @davidkpiano! -useActor
has been removed from the created actor context, you should be able to replace its usage withMyCtx.useSelector
andMyCtx.useActorRef
. -
#3947
5fa3a0c74
Thanks @davidkpiano! - Implementations for machines onuseMachine
anduseInterpret
hooks should go directly on the machine viamachine.provide(...)
, and are no longer allowed to be passed in as options.-const [state, send] = useMachine(machine, { - actions: { - // ... - } -}); +const [state, send] = useMachine(machine.provide({ + actions: { + // ... + } +}));
@xstate/react
will detect that the machine's config is still the same, and will not produce the "machine has changed" warning.