I have a component with a form that will add an item. When the form is submitted I'm dispatching an async action using redux, something like this:
_onSubmit(event) {
const { dispatch } = this.props;
const { data } = this.state;
event.preventDefault();
dispatch(addItem(data));
}
Now, my back-end will create a task with an id that I can track progress. Usually this given task will take a while to complete, so I want to show the notification bar.
For me to track that task, I need to retrieve the task id for this given task that is in progress. So I thought about adding a callback function so that I could get this information from the dispatcher, something like this:
_onSubmit(event) {
const { dispatch } = this.props;
const { data } = this.state;
event.preventDefault();
dispatch(addItem(data, (id) => console.log(id)));
}
But this feels kind of "hacky" as there is a two-way data communication going on.
Question: What is the redux way of achieving this?