I have defined two functions in my ActionCreator.js file First:
export const getAudioForVerification = ()=>{
return fetch(baseUrl+'audio',{
// Get Request
}
.then(response=>response.json());}
Second:
export const audioVerificationResult = (audioId,verificationResult) =>(dispatch)=>{
return fetch(baseUrl+'audio',{
// PUT Request
})
.then(response=>response.json());
}
MainFunction:
const mapDispatchToProps = dispatch => ({
getAudioForVerification: ()=>dispatch(getAudioForVerification),
audioVerificationResult: (audioId,verificationResult)=>dispatch(audioVerificationResult(audioId,verificationResult))
});
Q1: If I remove dispatch from my Second function: audioVerificationResult I get an error
Actions must be plain objects. Use custom middleware for async actions.
Why doesn't such an error appear for the first function as well?
Q2: The first function returns a promise (I can use .then in my MainComponent after I call this function) while the second one doesnot. Why?
I have started learning about Promises, Redux and Thunk (Web dev in general) quite recently. If the questions are too broad please direct me to a learning source.
Thank you for your time.