使用者工具

網站工具


learn:xstate

使用 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 清掉。

learn/xstate.txt · 上一次變更: 2022/11/29 13:39 由 admin_wi1d5ky

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki