Я пытаюсь проверить своих создателей действий, используя store
в консоли (в Chrome инструментах разработчика), но я получаю следующее сообщение об ошибке: Uncaught ReferenceError: receiveTodo is not defined
У меня есть дважды проверил мои орфографические / опечатки, а также экспортировал правильные модули, но я все еще не могу найти, где моя ошибка.
todo_actions. js
export const RECEIVE_TODOS = "RECEIVE_TODOS";
export const RECEIVE_TODO = "RECEIVE_TODO";
export const receiveTodos = todos => ({
type: RECEIVE_TODOS,
todos
});
export const receiveTodo = todo => ({
type: RECEIVE_TODO,
todo
});
root_reducer. js
import { combineReducers } from 'redux';
import todosReducer from './todos_reducer';
const rootReducer = combineReducers({
todos: todosReducer
});
export default rootReducer;
todos_reducer. js
import { RECEIVE_TODOS, RECEIVE_TODO } from '../actions/todo_actions';
// reducers/todos_reducer.js
const initialState = {
1: {
id: 1,
title: "wash car",
body: "with soap",
done: false
},
2: {
id: 2,
title: "wash dog",
body: "with shampoo",
done: true
}
};
const todosReducer = (state = initialState, action) => {
Object.freeze(state);
let nextState = {};
switch (action.type) {
case RECEIVE_TODOS:
action.todos.forEach(todo => nextState[todo.id] = todo);
return nextState;
case RECEIVE_TODO:
const newTodo = { [action.todo.id]: action.todo };
return Object.assign({}, state, newTodo);
default:
return state;
}
};
export default todosReducer;
store . js
import { createStore } from 'redux';
import rootReducer from '../reducers/root_reducer';
const configureStore = () => {
const store = createStore(rootReducer);
return store;
}
export default configureStore;
todo_redux.jsx (мой входной файл)
import React from 'react';
import ReactDOM from 'react-dom';
import configureStore from './store/store';
const store = configureStore();
window.store = store;
const Root = () => {
return (
<h1>Todos App</h1>
);
}
document.addEventListener("DOMContentLoaded", () => {
const root = document.getElementById('content');
ReactDOM.render(<Root/>, root);
});