[英]Unable to load the store in redux with some static data
I am trying to develop a web app using react, redux and webpack. 我正在尝试使用react,redux和webpack开发一个Web应用程序。 I am getting error while trying to load the store in redux with some static data.
尝试在Redux中使用一些静态数据加载存储时出现错误。
Please see the error below 请查看下面的错误
Can someone please help me solve the error. 有人可以帮我解决错误。
I have looked for similar question on stack overflow but the solution that they provided is what I already have in my application. 我一直在寻找有关堆栈溢出的类似问题,但他们提供的解决方案是我的应用程序中已有的解决方案。 Like people asked to include dependencies and make some changes in presets
就像有人要求添加依赖项并在预设中进行一些更改一样
Please see my code below: app.jsx: 请在下面查看我的代码:app.jsx:
store.dispatch(actions.changeDirection('Right', true));
store.dispatch(actions.addTitle());
var pages1 = [
{'1',
'slide1SubHeading1',
['point1', 'point2', 'point3']},
{'2', 'slide1SubHeading2', ['point1', 'point2', 'point3']}
];
var pages2 = [
{'1', 'slide2SubHeading1', ['point1', 'point2', 'point3']},
{'2', 'slide2SubHeading2', ['point1', 'point2', 'point3']}
];
var pages3 = [
{'1', 'slide3SubHeading1', ['point1', 'point2', 'point3']},
{'2', 'slide3SubHeading2', ['point1', 'point2', 'point3']}
];
store.dispatch(actions.addSlide('ReactSlide 1', false, true, pages1));
store.dispatch(actions.addSlide('ReactSlide 2', true, true, pages2));
store.dispatch(actions.addSlide('ReactSlide 3', true, false, pages3));
module in webpack.config.js: webpack.config.js中的模块:
module: {
loaders: [
{
loader: "babel-loader",
query: {
presets: ['react', 'es2015', 'stage-0']
},
test: /\.jsx?$/,
exclude: /(node_modules|bower_components)/
}
]
}
dependencies: 依赖项:
"dependencies": {
"axios": "^0.9.1",
"express": "^4.13.4",
"firebase": "^3.0.2",
"react": "^0.14.7",
"react-dom": "^0.14.7",
"react-router": "^2.0.0",
"babel-core": "^6.5.1",
"babel-loader": "^6.2.2",
"babel-preset-es2015": "^6.5.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
"css-loader": "^0.23.1",
"deep-freeze-strict": "^1.1.1",
"expect": "^1.14.0",
"foundation-sites": "6.2.0",
"jquery": "^2.2.1",
"moment": "^2.12.0",
"node-sass": "^3.4.2",
"node-uuid": "^1.4.8",
"react-addons-test-utils": "^0.14.6",
"react-redux": "^4.4.1",
"redux": "^3.3.1",
"redux-mock-store": "^1.0.3",
"redux-thunk": "^2.1.0",
"sass-loader": "^3.1.2",
"script-loader": "^0.6.1",
"style-loader": "^0.13.0",
"webpack": "^1.12.13",
"node-env-file": "^0.1.8"
}
When you do something like this 当你做这样的事情
var pages1 = [
{'1',
'slide1SubHeading1',
['point1', 'point2', 'point3']}
//...
]
You're creating a js array whose first element is the following js object 您正在创建一个js数组,其第一个元素是以下js对象
{'1',
'slide1SubHeading1',
['point1', 'point2', 'point3']}
However this is no valid js object, since a js object is composed of key and values, here you got only values. 但是,这不是有效的js对象,因为js对象由键和值组成,因此这里只有值。
To fix this you have to add key to your object, for instance : 要解决此问题,您必须向对象添加密钥,例如:
var pages1 = [
{pageNumber: '1',
heading: 'slide1SubHeading1',
points: ['point1', 'point2', 'point3']}
//...
]
(I just tried to guess key names from the content, but it's probably not the names you want). (我只是想从内容中猜测键名称,但这可能不是您想要的名称)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.