在 React 中,有限状态机是否取代了路由器的作用?
In react, does a finite state machine replace the role of a router?
我发现有限状态机可以替代在 React 应用程序中管理 UI 状态。我认为它们非常好,但我对如何使用它们有点困惑。
我应该为整个应用构建状态机还是在每个路由中构建小机器?
根据this spectrum discussion了解到可以用状态图代替路由器
例如,https://state-machine-yzgnuxxwmg.now.sh/
但是,https://statecharts.github.io/how-to-use-statecharts.html 的第一段建议在开始时在组件级别使用状态图。
When you first learn about statecharts, you might get the feeling that
statecharts can be used to describe the entire behaviour of an
application, all the way from which screens show as part of logging
in, to the state of each checkbox and text field in every screen, all
represented in a statechart. That would be a statechart from hell, and
an even bigger maintenance burden. Instead, the focus should be to get
a grip on the behaviour at the component level, whatever a component
might be. A single screen would be a component, for sure. A single
text field that might have some particular internal behaviour (e.g. it
changes color based on various flags like required or invalid) might
warrant that to be wrapped in a component with a statechart to
describe its behaviour.
我发现有限状态机可以替代在 React 应用程序中管理 UI 状态。我认为它们非常好,但我对如何使用它们有点困惑。
我应该为整个应用构建状态机还是在每个路由中构建小机器?
根据this spectrum discussion了解到可以用状态图代替路由器
例如,https://state-machine-yzgnuxxwmg.now.sh/
但是,https://statecharts.github.io/how-to-use-statecharts.html 的第一段建议在开始时在组件级别使用状态图。
When you first learn about statecharts, you might get the feeling that statecharts can be used to describe the entire behaviour of an application, all the way from which screens show as part of logging in, to the state of each checkbox and text field in every screen, all represented in a statechart. That would be a statechart from hell, and an even bigger maintenance burden. Instead, the focus should be to get a grip on the behaviour at the component level, whatever a component might be. A single screen would be a component, for sure. A single text field that might have some particular internal behaviour (e.g. it changes color based on various flags like required or invalid) might warrant that to be wrapped in a component with a statechart to describe its behaviour.