简体   繁体   English

类型错误:无法读取未定义 React 的属性“任何”

[英]TypeError: Cannot read property 'any' of undefined React

I'm new to React and I'm trying to make small app by following a Udemy tutorial.我是 React 的新手,我正在尝试按照 Udemy 教程制作小应用程序。 The application contains a form.该应用程序包含一个表单。 When I import redux-form library into my project, I got the below console error.当我将redux-form库导入我的项目时,出现以下控制台错误。

在此处输入图片说明 在此处输入图片说明

package.json包.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 contains the form. 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);

also imported redux-form in reducers _> index.js还在减速器中导入了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;

Use version 5.3.6.使用版本 5.3.6。 It will definitely solve the problem.它肯定会解决问题。

I ones had same error.我有同样的错误。 How I resolved it was to upgrade the redux-form to v5.2.6.我的解决方法是将 redux-form 升级到 v5.2.6。 Then stop the server in your terminal using Ctrl +c, run npm i to bring in redux -form dependences.然后使用 Ctrl +c 在终端中停止服务器,运行 npm i 以引入 redux -form 依赖项。 then restart your project.然后重新启动您的项目。

This should fix the error.这应该修复错误。 I hope this helps.我希望这有帮助。

Installing updates using package-manager is not enough.使用包管理器安装更新是不够的。 You need to reinstall your localhost after updating redux-form.更新 redux-form 后,您需要重新安装 localhost。 using:使用:

  • Ctrl + 'C' Ctrl + 'C'
  • npm i我的
  • npm start启动

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM