learn:xstate
差異處
這裏顯示兩個版本的差異處。
learn:xstate [2022/11/29 13:35] – 建立 admin_wi1d5ky | learn:xstate [2022/11/29 13:39] (目前版本) – admin_wi1d5ky | ||
---|---|---|---|
行 3: | 行 3: | ||
## useMachine & useInterpret | ## useMachine & useInterpret | ||
- | useInterpret 是 static、獨立於 react component lifetime cycle 之外的,所以在 context 情況下不會一直重新生成 | + | `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