redux-form 从不调用本机应用程序的验证
redux-form never calls validation for react native app
我完全希望 "look, your forgot a comma there" 或一些愚蠢的东西可以解决这个问题,但我真的看不到它。我已将问题简化为只有一种 redux 形式的基本 React 本机应用程序。
import React from 'react'
import { createStore, applyMiddleware } from 'redux'
import logger from 'redux-logger'
import { Provider } from 'react-redux'
import { Text, View, TextInput, Button } from 'react-native'
import { combineReducers } from 'redux'
import { reducer as formReducer, Field } from 'redux-form'
import { reduxForm } from 'redux-form'
const rootReducer = combineReducers({ forms: formReducer })
const store = createStore(rootReducer, {}, applyMiddleware(logger))
const validate = (values) => {
const errors = {}
if (!values.name) errors.name = 'Required'
if (!values.email) errors.email = 'Required'
return errors
}
const renderInput = ({ input: { onChange, ...restInput } }) => {
return <TextInput onChangeText={onChange} {...restInput} />
}
class MyForm extends React.Component {
submit = (values) => console.log('Submitting ', values)
render() {
const { handleSubmit } = this.props
return (
<View style={{ padding: 20 }}>
<Text>Please fill in this form:</Text>
<Field name='name' component={renderInput} />
<Field name='email' component={renderInput} />
<Button title='Go' onPress={handleSubmit(this.submit)} />
</View>
)
}
}
const MyConnectedForm = reduxForm({
form: 'myform',
validate
})(MyForm)
export default class App extends React.Component {
render() {
return (
<Provider store={store}>
<MyConnectedForm />
</Provider>
)
}
}
我可以看到事件:
@@redux-form/CHANGE
@@redux-form/BLUR
正在被解雇,并且表单的 redux 状态发生了变化。然而,validate 只在第一次渲染时被调用一次,而且再也不会调用。此外,当我按下按钮时,将使用一个空对象调用提交函数,而不是像我期望的那样调用表单的值。
使用的版本:
- redux: 3.7.2
- redux 形式:7.3.0
- 反应:16.3.1
- 本机反应:0.55.4
几乎和错位的逗号一样糟糕。我使用了密钥,forms,然后是 form.
我完全希望 "look, your forgot a comma there" 或一些愚蠢的东西可以解决这个问题,但我真的看不到它。我已将问题简化为只有一种 redux 形式的基本 React 本机应用程序。
import React from 'react'
import { createStore, applyMiddleware } from 'redux'
import logger from 'redux-logger'
import { Provider } from 'react-redux'
import { Text, View, TextInput, Button } from 'react-native'
import { combineReducers } from 'redux'
import { reducer as formReducer, Field } from 'redux-form'
import { reduxForm } from 'redux-form'
const rootReducer = combineReducers({ forms: formReducer })
const store = createStore(rootReducer, {}, applyMiddleware(logger))
const validate = (values) => {
const errors = {}
if (!values.name) errors.name = 'Required'
if (!values.email) errors.email = 'Required'
return errors
}
const renderInput = ({ input: { onChange, ...restInput } }) => {
return <TextInput onChangeText={onChange} {...restInput} />
}
class MyForm extends React.Component {
submit = (values) => console.log('Submitting ', values)
render() {
const { handleSubmit } = this.props
return (
<View style={{ padding: 20 }}>
<Text>Please fill in this form:</Text>
<Field name='name' component={renderInput} />
<Field name='email' component={renderInput} />
<Button title='Go' onPress={handleSubmit(this.submit)} />
</View>
)
}
}
const MyConnectedForm = reduxForm({
form: 'myform',
validate
})(MyForm)
export default class App extends React.Component {
render() {
return (
<Provider store={store}>
<MyConnectedForm />
</Provider>
)
}
}
我可以看到事件:
@@redux-form/CHANGE @@redux-form/BLUR
正在被解雇,并且表单的 redux 状态发生了变化。然而,validate 只在第一次渲染时被调用一次,而且再也不会调用。此外,当我按下按钮时,将使用一个空对象调用提交函数,而不是像我期望的那样调用表单的值。
使用的版本:
- redux: 3.7.2
- redux 形式:7.3.0
- 反应:16.3.1
- 本机反应:0.55.4
几乎和错位的逗号一样糟糕。我使用了密钥,forms,然后是 form.