【发布时间】:2018-10-23 16:21:02
【问题描述】:
我是 React 新手,我正在尝试按照 Udemy 教程制作小应用程序。该应用程序包含一个表格。当我将redux-form 库导入我的项目时,出现以下控制台错误。
package.json
"dependencies": {
"axios": "^0.18.0",
"babel-preset-stage-1": "^6.1.18",
"lodash": "^3.10.1",
"react": "16.3.2",
"react-countdown-now": "^1.3.0",
"react-dom": "16.3.2",
"react-redux": "5.0.7",
"react-router": "^3.2.0",
"redux": "4.0.0",
"redux-form": "^4.1.3",
"redux-promise": "^0.5.3"
}
post_new.js 包含表单。
import React, { Component } from 'react';
import { reduxForm } from 'redux-form';
class PostsNew extends Component {
render() {
return (
<form onSubmit={handleSubmit}>
<h3>Create a new post</h3>
<div className="form-group">
<label>Title</label>
<input type="text" className="form-control" />
</div>
<div className="form-group">
<label>Categories</label>
<input type="text" className="form-control"/>
</div>
<div className="form-group">
<label>Content</label>
<textarea className="form-control"/>
</div>
<button type="submit" className="btn btn-primary">Submit</button>
</form>
);
}
}
export default reduxForm(
{
form: 'PostsNewForm',
fields: ['title','categories','content']
}
)(PostsNew);
还在减速器中导入redux-form _> index.js
import { combineReducers } from 'redux';
import PostReducer from './reducer_posts';
import { reducer as formReducer } from 'redux-form';
const rootReducer = combineReducers({
posts: PostReducer,
form: formReducer
});
export default rootReducer;
【问题讨论】:
-
尝试更新你的 redux-form。您已经在使用版本 5 n v6。 redux-form.com/6.7.0/docs/migrationguide.md
-
如果您在导入 redux-form 之前没有任何错误,那么它肯定与您拥有的 redux-form 版本存在一些兼容性问题。尝试更改版本。'
-
我已将 redux-form 版本更新到 v7。现在它是
"redux-form": "^7.3.0"。但错误仍然存在。 -
听起来你在某些时候正在使用一个对象并试图读取它们的键
any。当您尝试访问像this.props.data.any这样的嵌套对象中的道具时,这很常见,其中this.props.data在某些时候是undefined
标签: javascript reactjs react-redux typeerror