我試圖做簡單的形式呈現,但我總是得到這個錯誤終極版形式V6,未知道具消息
Unknown props `input`, `meta` on <input> tag.
我以前研究這個問題,並沒有發現任何東西,除了GitHub的討論,這些討論實際上會拋出大約4或5種不同的實現方式,而沒有達成共識,我也按照這種方式跟蹤了v6文檔的實現,但無濟於事。有什麼建議麼?
我使用的是v6.2.0,這是我發佈本文時的最新版本。
我直接從這裏的示例粘貼,http://redux-form.com/6.0.0-alpha.15/examples/syncValidation/,仍然出錯。 (我附上下面的代碼)
import React from 'react'
import { Field, reduxForm } from 'redux-form'
const validate = values => {
const errors = {}
if (!values.username) {
errors.username = 'Required'
} else if (values.username.length > 15) {
errors.username = 'Must be 15 characters or less'
}
if (!values.email) {
errors.email = 'Required'
} else if (!/^[A-Z0-9._%+-][email protected][A-Z0-9.-]+\.[A-Z]{2,4}$/i.test(values.email)) {
errors.email = 'Invalid email address'
}
if (!values.age) {
errors.age = 'Required'
} else if (isNaN(Number(values.age))) {
errors.age = 'Must be a number'
} else if (Number(values.age) < 18) {
errors.age = 'Sorry, you must be at least 18 years old'
}
return errors
}
const renderField = props => (
<div>
<label>{props.placeholder}</label>
<div>
<input {...props}/>
{props.touched && props.error && <span>{props.error}</span>}
</div>
</div>
)
const SyncValidationForm = (props) => {
const { handleSubmit, pristine, reset, submitting } = props
return (
<form onSubmit={handleSubmit}>
<Field name="username" type="text" component={renderField} placeholder="Username"/>
<Field name="email" type="email" component={renderField} placeholder="Email"/>
<Field name="age" type="number" component={renderField} placeholder="Age"/>
<div>
<button type="submit" disabled={submitting}>Submit</button>
<button type="button" disabled={pristine || submitting} onClick={reset}>Clear Values</button>
</div>
</form>
)
}
export default reduxForm({
form: 'syncValidation', // a unique identifier for this form
validate // <--- validation function given to redux-form
})(SyncValidationForm)
console.log(this.props);在渲染頂部併發布結果 – Chase
對象{anyTouched:false,asyncValidating:false,dirty:false,error:undefined,form:「syncValidation」...} –
我也嘗試過但這沒有註冊輸入變化(看不到你正在打字),並沒有錯誤或驗證檢查發生 –