I'm using redux-saga to list and update a list of items stored in a remote server. And I would like to create an item and then to list the items. That is:
import { connect } from 'react-redux'
const NewItemDialog = ({ createItem, listItems }) => {
const onAccept = () => {
// this won't work, since 'dispatch' is synchronous
await createItem('New item')
listItems()
}
// ... snip ...
}
const mapStateToProps = (state) => {
items: state.items
}
const mapDispatchToProps = (dispatch) => ({
createItem: (name: string) => dispatch(createItem(name)),
listItems: () => dispatch(listItems())
})
export default connect(mapStateToProps, mapDispatchToProps)(NewItemDialog)
What is the proper way to wait for an action to be completed?