As seen in this answer, passing state to an ActionCreator is considered an anti-pattern. So is accessing the state with Redux Thunk Middleware. I'm wondering how to solve the following (popular) scenario:
I'm fetching items from a server, based on filters from a search form on the frontend. Naturally, I need to pass the filters to my server, so I'm doing this in my action creator
export function getResults(filters){
return Axios.get('localhost:80/getresults/',{params:filters}).then(
// do something with results here.
)
}
But this is considered an anti-pattern because filters
is coming from the store.
Alternatively, I could use redux thunk like this:
export function getResults(){
return function(dispatch,getState){
var filters = getState().reducer.filters;
return Axios.get('localhost:80/getresults/',{params:filters}).then(
// do something with results here.
)
}
}
This is also considered an anti-pattern because I'm accessing state.
So how would I implement it the correct way? Should I do the ajax call somewhere else entirely?