Javascript TypeError:无法读取属性';任何';未定义的反应
我是一个新的反应者,我正试图按照我的教程制作一个小应用程序。应用程序包含一个表单。当我将库导入到我的项目中时,出现了以下控制台错误 package.jsonJavascript TypeError:无法读取属性';任何';未定义的反应,javascript,reactjs,react-redux,typeerror,Javascript,Reactjs,React Redux,Typeerror,我是一个新的反应者,我正试图按照我的教程制作一个小应用程序。应用程序包含一个表单。当我将库导入到我的项目中时,出现了以下控制台错误 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",
"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);
使用5.3.6版。
它肯定会解决问题。使用软件包管理器安装更新是不够的。 更新redux表单后,需要重新安装本地主机。 使用:
- Ctrl+C'
- npm i
- npm启动
我希望这有帮助。尝试更新您的redux表单。您已经在使用版本5 n v6。如果在导入redux表单之前没有出现任何错误,则与现有redux表单版本之间肯定存在一些兼容性问题。尝试更改版本。我已将redux表单版本更新到v7。现在它是
“redux表单”:“^7.3.0”
。但错误仍然存在。听起来好像您在某个时候使用对象并试图读取它们键any
。当您试图访问嵌套对象(如This.props.data.any
whereThis.props.data
中的一个道具时,这是非常常见的,在某个点上,未定义
我不认为存在redux表单
v5.2.6。您是对的,我的意思是说redux表单:“^5.3.6”。谢谢你的更正
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;