Tutorial 2: Handle Side Effects
For a sign-up form, we might want to call an API to validate the username while the user typing.
First, let's create a fake username validation function to simulate the async request.
Then we will add a valid
state to the user model and add mutation accordingly
To call remote API on each setUsername
mutation, we need to define a side-effect for it:
Please note in the above example how it retrieves the payload of a mutation.
The side-effect function will run on every mutations.setUsername
and it will call the async function to validate username and update valid
state accordingly.
See the full running example here
Last updated
Was this helpful?