amplitude / redux-query

A library for managing network state in Redux
https://amplitude.github.io/redux-query
Other
1.1k stars 67 forks source link

Problem with CRA code and the query middleware? #201

Closed TheCarlR closed 4 years ago

TheCarlR commented 4 years ago

In order to iron out some issues, I recreated the hacker-news sample in typescript.

https://github.com/TheCarlR/redux-query/tree/feature/hacker-news

It's based on the yarn create react-app my-app --template redux-typescript CRA template from redux.

I kept the original sample code and added the hacker-news, so that the store would be more real life like. When I run it, the original code works, with the exception of the async action that now fails. If I comment out the middleware: [queryMiddleware(superagentInterface, getQueries, getEntities)], line in store.ts it works again. (Obviously the news isn't loaded.)

The error is Error: Actions must be plain objects. Use custom middleware for async actions. The action that breaks is a thunk, and is from the redux boiler plate, so I think it should be implemented correctly.

Do you have any idea why this is happening?

TheCarlR commented 4 years ago

Fixed by changing syntax to middleware: getDefaultMiddleware => getDefaultMiddleware().concat(queryMiddleware(superagentInterface, getQueries, getEntities)),

This prevents the default middleware from being replaced.