# 与 RxJS 一起使用
¥Usage with RxJS
这些 XState v4 文档不再维护
XState v5 现已推出!阅读有关 XState v5 的更多信息 (opens new window) 和 查看 XState v5 文档 (opens new window)。
¥XState v5 is out now! Read more about XState v5 (opens new window) and check out the XState v5 docs (opens new window).
解释机(即 service
)是可订阅的。
¥The interpreted machine (i.e., service
) is subscribable.
import { createMachine, interpret } from 'xstate';
import { from } from 'rxjs';
const machine = createMachine(/* ... */);
const service = interpret(machine).start();
const state$ = from(service);
state$.subscribe((state) => {
// ...
});