Reputation: 281
I have got the error message
"undefined is not an object(evaluating 'CategoryAction2.default.categoryView')" on executing the below code,
ConfigureStore.js:
import {createStore, applyMiddleware} from 'redux';
import reducers from '../reducers';
import thunk from 'redux-thunk';
var middlewares = applyMiddleware(thunk);
export default function configureStore(initialState) {
return createStore(reducers, initialState, middlewares);
}
CategoryContainer.js:
import React, { Component } from 'react';
import stores from '../stores/ConfigureStore';
import CategoryAction from '../actions/CategoryAction';
stores.dispatch(CategoryAction.categoryView());
class CategoryContainer extends Component {
}
CategoryAction.js
import * as actionTypes from './ActionTypes';
import AppConstants from '../constants/AppConstants';
export function categoryView() {
const categories = ['Health', 'Built-in'];
return {
type: "CATEGORY_VIEW",
categories: categories
};
}
CategoryReducer.js:
const initialState = {
categories:[],
}
export default function categoryReducer (state = initialState, action) {
switch (action.type) {
case CATEGORY_VIEW:
return Object.assign({}, state, {
categories: action.categories
});
}
}
The below line in CategoryContainer.js raises the error message, stores.dispatch(CategoryAction.categoryView());
Kindly assist to solve the issue.
Upvotes: 2
Views: 6051
Reputation: 4097
In CategoryContainer.js, you need to import the specific member (or all members) of CategoryActions.js. Should be one of the two options below:
import * as CategoryAction from '../actions/CategoryAction';
// or
import { categoryView } from '../actions/CategoryAction';
stores.dispatch(categoryView());
Upvotes: 3