# 使用 xstate 的一些筆記 ## useMachine & useInterpret `useInterpret` 是 static、獨立於 react component lifetime cycle 之外的,所以在 context 情況下不會一直重新生成 而 `useMachine` 在 component 一直 mount & unmount 的情況下,也會一直重新產生 machine。 ## spawn & invoke spawn 和 invoke 都可以產生 child machine,但有差別 spawn 產生的 child machine 是全 state 共用的,就算離開了某個 state,也不會使產生出來的 child machine 被清掉。 而 invoke 則是跟著 state 的,離開了該 state,xstate 就會把該 state invoke 出來的 child machine 清掉。