您可以在 xstate 中将嵌套状态与字符串路径匹配吗?

Can you match a nested state with string paths in xstate?

来自 @xstate/react GitHub 存储库:

... for hierarchical and parallel machines, the state values will be objects, not strings. In this case, it's better to use state.matches(...)

看起来像这样:

if (current.matches({ loading: 'user' })) {
  return /* ... */;
}

但是你可以用 "loading.user" 替换 { loading: 'user' } 吗?

当然!至少对于当前版本的 xstate (4.6.7) 和 @xstate/react (0.8.1),下面的 if 语句是等价的:

if (current.matches({ loading: 'user' })) {
  return /* ... */;
}
if (current.matches("loading.user")) {
  return /* ... */;
}