File tree Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Expand file tree Collapse file tree 2 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
1010
1111For a steady stream of TILs, [ sign up for my newsletter] ( https://tinyletter.com/jbranchaud ) .
1212
13- _ 1140 TILs and counting..._
13+ _ 1141 TILs and counting..._
1414
1515---
1616
@@ -1336,6 +1336,7 @@ _1140 TILs and counting..._
13361336
13371337- [ Define Event That Does Internal Self Transition] ( xstate/define-event-that-does-internal-self-transition.md )
13381338- [ Inline Actions vs Actions In Machine Options] ( xstate/inline-actions-vs-actions-in-machine-options.md )
1339+ - [ Simple States And Composite States] ( xstate/simple-states-and-composite-states.md )
13391340- [ Use An XState Machine With React] ( xstate/use-an-xstate-machine-with-react.md )
13401341
13411342### YAML
Original file line number Diff line number Diff line change 1+ # Simple States And Composite States
2+
3+ XState allows you to build [ hierarchical state
4+ machines] ( https://xstate.js.org/docs/guides/hierarchical.html ) . A hierarchical
5+ state machine is one where there are substates nested under states.
6+
7+ States with nothing nested under them are _ simple states_ . States that have
8+ substates are _ composite states_ .
9+
10+ ``` javascript
11+ const machine = createMachine ({
12+ // Starting State
13+ initial: " active" ,
14+ // Starting Context
15+ context: { count: 0 },
16+ // States
17+ states: {
18+ inactive: {
19+ always: { target: " active" },
20+ },
21+ active: {
22+ on: {
23+ SWITCH_COUNT_DIRECTION : {
24+ actions: [" logSwitch" , " consoleLogSwitch" ],
25+ },
26+ COUNT : {
27+ actions: " changeCount" ,
28+ },
29+ },
30+ initial: " increment" ,
31+ states: {
32+ increment: {
33+ on: {
34+ SWITCH_COUNT_DIRECTION : " decrement" ,
35+ },
36+ },
37+ decrement: {
38+ on: {
39+ SWITCH_COUNT_DIRECTION : " increment" ,
40+ },
41+ },
42+ },
43+ },
44+ },
45+ });
46+ ```
47+
48+ - The ` inactive ` state is a _ simple state_ . There is nothing nested under it.
49+ - The ` active ` state is a _ composite state_ . There are two substates
50+ (` increment ` and ` decrement ` ) nested under it.
51+ - The ` increment ` and ` decrement ` states are both _ simple states_ . Nothing is
52+ nested under them.
You can’t perform that action at this time.
0 commit comments