score:0
Your action looks like it is using redux-thunk
but your config says otherwise.
I'm new to react as well so I'm not 100% sure, but try this configuration (after installing redux-thunk
of course):
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import { createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import ReduxPromise from 'redux-promise';
import App from './components/app';
import reducers from './reducers';
const createStoreWithMiddleware = applyMiddleware(thunk, ReduxPromise)(createStore);
ReactDOM.render(
<Provider store={createStoreWithMiddleware(reducers)}>
<App />
</Provider>,
document.querySelector('.container')
);
score:1
A great article that can help is redux 4 ways.
Regarding the code.
With redux-promise (which I see that you are using now) you should write:
export const getNewsAPI = () => {
return {
type: 'API_REQUEST',
options: {
method: 'GET',
endpoint: `https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey=${API_KEY}`,
actionTypes: {
success: types.GET_NEWS_API_SUCCESS,
error: types.GET_NEWS_API_ERROR
}
}
Or, with redux-thunk:
Instead of:
export const getNewsAPI = () => {
return (dispatch, getState) => {
dispatch({
type: 'API_REQUEST',
options: {
method: 'GET',
endpoint: `https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey=${API_KEY}`,
actionTypes: {
success: types.GET_NEWS_API_SUCCESS,
error: types.GET_NEWS_API_ERROR
}
}
});
}
}
Use:
function actionCreator() {
return {
type: 'API_REQUEST',
options: {
method: 'GET',
endpoint: `https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey=${API_KEY}`,
actionTypes: {
success: types.GET_NEWS_API_SUCCESS,
error: types.GET_NEWS_API_ERROR
}
}
}
}
and:
export const getNewsAPI = () => {
return function (dispatch) {
dispatch(actionCreator())
}
Source: stackoverflow.com
Related Query
- React Redux Saga: Actions must be plain objects. Use custom middleware for async actions
- react & redux with hooks: Actions must be plain objects. Use custom middleware for async actions
- React redux Actions must be plain objects. Use custom middleware for async actions
- Redux Actions must be plain objects. Use custom middleware for async actions
- Redux Error Actions must be plain objects. Use custom middleware for async actions
- Redux thunk - Error ยท Actions must be plain objects. Use custom middleware for async actions even with dispatch an object with key type
- Redux error: Actions must be plain objects. Use custom middleware for async actions
- Problem with redux middleware - Error: Actions must be plain objects. Use custom middleware for async actions
- Async Action Redux Unhandled Rejection (Error): Actions must be plain objects. Use custom middleware for async actions
- Use custom middleware for async actions. Actions must be plain objects
- React-Redux: Actions must be plain objects. Use custom middleware for async actions
- Unit test: Actions must be plain objects. Use custom middleware for async actions
- CreateAsyncThunk Error: Actions must be plain objects. Use custom middleware for async actions
- React-Redux-Saga: Actions must be plain objects. Use custom middleware for async actions
- React-Redux - Unhandled Rejection (Error): Actions must be plain objects. Use custom middleware for async actions
- React-Redux: Actions must be plain objects. Use custom middleware for async actions Error
- Actions must be plain objects. Use custom middleware for async actions.how to solve this
- react-redux Error: Actions must be plain objects. Use custom middleware for async actions
- redux-observable + socket.io: Actions must be plain objects. Use custom middleware for async actions
- Error: Actions must be plain objects. Use custom middleware for async actions.
- Actions must be plain objects. Use custom middleware for async actions - Lost Here
- Actions must be plain objects. Use custom middleware for async actions
- How to fix: Error: Actions must be plain objects. Use custom middleware for async actions.?
- Redux-Thunk Error: Actions must be plain objects. Use custom middleware for async actions
- Error: Actions must be plain objects. Use custom middleware for async actions. But I don`t have async functions
- Redux Thunk + Axios "Actions must be plain objects. Use custom middleware for async actions."
- React/Redux: Error: Actions must be plain objects. Use custom middleware for async actions
- React-Reudx: Actions must be plain objects. Use custom middleware for async actions
- redux-observable: Actions must be plain objects. Use custom middleware for async actions
- Actions must be plain objects. Use custom middleware for async actions Saga thunk I do have so far in my store
More Query from same tag
- Static method is undefined in ES6 classes with a decorator in reactjs
- How to pass on a start value to input?
- How to make mixins work in react es6?
- React js Spring boot and findbyId
- Displaying one of multiple components best practices
- React: cant get output inside a functional component
- Is there a way to include the react-select dropdown near the body tag
- React-Grid-Layout elements handle jumps if there are other elements in the app root in react app
- Any way to pluralize with translations using formatjs?
- embed twitter timeline in react app
- useLocation can't be mocked with jest.fn() (while useHistory can be)
- Experiencing compile error with a higher order component's mapState function that returns an object within an object
- Material-UI: flip:false doesn't work as expected
- Testing React Component with Jest Uncovered lines
- Jest throwing render error when loading functional child component
- ReduxForm Field component not working with ReactTable Cell property in column Headers
- Testing nested components in React
- Redux Dev Tools not working for large action payload
- How to post a javascript array to MongoDB from react app?
- React - Unexpected token u in JSON at position 5
- How to make a layout with Styled Components?
- How to render a grouped list using react
- Open and close expandable button in list view
- Why does calling the set function of a useState hook apply immediately in async functions?
- Why does a count using React Hooks useState() alternate between two numbers?
- Material UI Themes and Hyperstack
- Unable to initialize when loading Firebase SDKs from reserved URLs
- Using redux's useDispatch in a custom hook yields an error
- Is it possible to place simple app with React and MobX within one html page?
- Turn object from DB into a Map()