Итак, я использую реакцию + redux, и я продолжаю получать следующую ошибку: «Невозможно прочитать свойство», затем «неопределенного». По какой-то причине обещание не возвращается. Я также особенно новичок в том, чтобы использовать редукс.Невозможно прочитать свойство 'then' of undefined
Reducer
import { merge } from 'lodash';
import * as APIutil from '../util/articles_api_util';
import {
ArticleConstants
} from '../actions/article_actions';
const ArticlesReducer = (state = {}, action) => {
switch (action.type) {
case ArticleConstants.RECEIVE_ALL_ARTICLES:
debugger
return merge({}, action.articles);
default:
return state;
}
};
export default ArticlesReducer;
магазин
import { createStore, applyMiddleware } from 'redux';
import RootReducer from '../reducers/root_reducer';
import thunk from 'redux-thunk';
import * as APIUtil from '../util/articles_api_util';
export const ArticleConstants = {
RECEIVE_ALL_ARTICLES: "RECEIVE_ALL_ARTICLES",
REQUEST_ALL_ARTICLES: "REQUEST_ALL_ARTICLES"
}
Действия
export function fetchArticles() {
return function(dispatch) {
return APIUtil.fetchArticles().then(articles => {
dispatch(receiveAllArticles(articles));
}).catch(error => {
throw(error);
});
};
}
export const requestAllArticles=() => ({
type: REQUEST_ALL_ARTICLES
});
export const receiveAllArticles = articles => ({
type: RECEIVE_ALL_ARTICLES,
articles
});
const configureStore = (preloadedState = {}) => (
createStore(
RootReducer,
preloadedState,
applyMiddleware(thunk)
)
);
export default configureStore;
ОРСП TIL
export const fetchArticles = (success) => {
$.ajax({
method: 'GET',
url: `/api/articles`,
success,
error:()=> (
console.log("Invalid Article")
)
});
};
Вы можете также разделить 'метод APIUtil.fetchArticles' – Swapnil
@Swapnil я добавил APIUtil – acampbe222
ли вы попробовать использовать' .done' вместо '.then' – Swapnil