How to dispatch the redux function in react async call. When I call the dispatch function dispatch(updatingcontact()
, I'm getting error that dispatch is not defined.
const UpdateContact = async (URL, method, type, address) => {
dispatch(updatingcontact()
const APIResponse = await fetch(URL, {
method: POST,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
"webContacts": {
"address": address
}
})
})
.then(response => {
if (!response.ok) {
return Promise.reject(response.statusText);
}
return response.json();
})
.then(status => {
return status
})
.catch(error => {
console.log(error);
});
}
I just want to call the updatingcontact()
function inside the UpdateContact
and call the reducer to display the updating message in UI.
function updatingcontact() {
return {
type: ACTIONTYPES.UPDATING_CONTACT
}
}