react-waterfall-example
react-waterfall-example copied to clipboard
Demonstrate new syntax for actions
Hi, this demonstrates a new syntax for actions which looks like this:
const store = {
actions: {
// Set state multiple times in an action, e.g. for loading indicator
doSomething: async ({ state, setState }, user) => {
// Set state using setState
setState({ loading: true })
const response = await fetch('https://' + state.remote + '/users/' + user)
const body = await response.json()
// Set state by returning new state
return {
loading: false,
user: { avatar: body.avatar_url }
}
}
}
}