This section uses parts of the code created in previous tutorial parts.
Use selectors instead, where possible
This feature can be usually replaced with async selectors and it is recommended to do so.
watch reaction can also be async function.
Let's say, each time user opens new todo, we want to check all attachments and warn user if they contain viruses.
We could write such watch like:
Few notes here.
- Again, after each
awaitphase - reaction will check if any previously used values changed. If this is the case - reaction will instantly cancel next steps and start over
- We're using
selector.value. This is because we're in async function, so there is no need to suspend current reaction on each async read attempt.
In async functions always use
const value = await selector.promise instead of
const value = selector.value.
selector.read inside async functions will throw an error.