gpt4 book ai didi

javascript - redux-form 无法读取未定义的属性 'any'

转载 作者:行者123 更新时间:2023-11-29 10:29:47 25 4
gpt4 key购买 nike

我对 react-native 中的 redux-from 有疑问。我想为我的应用程序实现一个登录表单。从网上的教程中我写了这段代码但是有这个错误的问题

Cannot read property 'any' of undefined

Error screenshot

Package.json

"dependencies": {
"react": "16.2.0",
"react-addons-update": "^15.6.2",
"react-native": "0.53.0",
"react-redux": "^5.0.6",
"redux": "^3.7.2",
"redux-form": "^5.3.2",
"redux-persist": "^3.2.2"
},

这是我的Login.js组件

import React, { Component } from 'react';
import { StyleSheet, Text, View, TextInput, TouchableOpacity } from 'react-native';
import { reduxForm } from "redux-form";

class Login extends Component {
onSignIn() {
var { email, password } = this.props.fields;
console.log(email.value, password.value);
}

render(){
var {fields: {email, password}} = this.props;
return (
<View style={styles.container}>
<View style={styles.titleContainer} >
<Text style={styles.title} >ToDo</Text>
</View>
<View style={styles.fields} >
<TextInput
{...email}
placeholder="Email"
style={styles.TextInput}
/>
</View>
<View style={styles.fields} >
<TextInput
{...password}
placeholder="Password"
style={styles.TextInput}
/>
</View>
<View style={styles.buttonContainer} >
<TouchableOpacity>
<Text style={styles.button} onPress={this.onSignIn} >
Signin
</Text>
</TouchableOpacity>
<TouchableOpacity>
<Text style={styles.button}>
Signup
</Text>
</TouchableOpacity>
</View>
</View>
);
}
}


const styles = StyleSheet.create({
...
});

var validate = (formProps) => {
var errors = {};

return errors;
}

export default reduxForm({
form: 'login',
fields: ['email', 'password'],
validate: validate
}, null, null)(Login);

我的 reducer index.js

import update from "react-addons-update";
import { combineReducers } from "redux";
import { reducer as formReduser } from "redux-form";

module.exports = combineReducers({
form: formReduser
})

最佳答案

看起来那个版本的 redux-form 不支持 react 16。Prop 类型已经被移动到一个单独的包中。尝试将 redux-form 升级到 5.3.6 或更高版本。

关于javascript - redux-form 无法读取未定义的属性 'any',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48822741/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com