Sometimes you need to react to changes to state. Typically you want to run some imperative logic related to something in the state changing.
1
reaction(
2
// Access and return some state to react to
3
(state)=> state.foo,
4
5
// Do something with the returned value
6
(foo)=>{},
7
8
{
9
// If you return an object or array from the state you can set this to true.
10
// The reaction will run when any nested changes occur as well
11
nested:false,
12
13
// Runs the reaction immediately
14
immediate:false
15
}
16
)
Copied!
There are two points of setting up reactions in Overmind.
onInitializeOvermind
The onInitializeOvermind action is where you set up reactions that lives throughout your application lifetime. The reaction function returns a function to dispose it. That means you can give effects the possibility to create and dispose of reactions in any action.