I am a beginner in Redux and JavaScript and just came across this issue,
When I use the line
dispatch({type: 'REQUEST_START'});
it works fine, but when I write it like this:
dispatch(requestStart);
No actions are being fired!
Any suggestions on why this might be happening? It's strange because it works in another app that I have.
This is the code I am working with:
import { booksActionTypes } from './books.types';
export const requestStart = () => ({
type: booksActionTypes.REQUEST_START,
});
export const requestSuccess = books => ({
type: booksActionTypes.REQUEST_SUCCESS,
payload: books,
});
export const requestFailure = errMsg => ({
type: booksActionTypes.REQUEST_FAILURE,
payload: errMsg,
});
export const actionCreators = {
// "applicationUrl": "http://localhost:51374", http://erikswed.ddns.net:8965/api/BooksXml/getbooks/fromall/?title=dep&author=&genre=&price=
// "sslPort": 44378
requestBooks: (book) => async (dispatch, getState) => {
dispatch({type: 'REQUEST_START'});
var queryString = Object.keys(book)
.map((key) => {
return encodeURIComponent(key) + "=" + encodeURIComponent(book[key]);
})
.join("&");
var url = "http://erikswed.ddns.net:8965/api/BooksXml/getbooks/fromall/?" + queryString;
console.log(`url: `, url);
await fetch(url)
.then((res) => res.json())
.then((booksList) => {
dispatch(requestSuccess, booksList);
})
.catch((rejected) => {
console.log(rejected);
dispatch(requestFailure, rejected);
});
// const response = await fetch(url);
// const booksList = await response.json();
},
};