This section uses parts of the code created in previous tutorial parts.
If you've read previous Views chapter, you might already have some idea how watching works in Statek, but let's focus on it a bit more
Having the todos store ready, we can start watching it providing reaction function or using it inside react
This will give us such output:
watch reaction function will be called for the first time instantly. Manual reaction calling will be covered in next sections of this docs.
While watching is running or we're rendering any component using the store, we can modify the store in any way and reactions watching it will be called automatically
Reaction and components using the store will be instantly called and new output will be
At any point, we can stop watching reaction started with
watch be using stop function returned from
Reactions and re-renders are triggered only when used data changes.
If some part of the store is changed, but it was never used by some component or reaction - it'll not cause it to be called again.
Let's see it in our example by extending our store with some new data
Now, let's start using it
Note we're now using only
todos.sharedWith part of the store, which means we can safely ignore changes made to
Now, let's add new todo:
Changes will not triger reactions or components to be called again, as
.list part of the store was never used.
If we'll however call
It will trigger reaction/component described above