내 프로젝트 중 하나에서 Redux Form을 사용하고 있습니다. (사실은 Rally Coding에서 동적 인 파일을 복사하는 것입니다.) 그러나 this.props.fields에 액세스 할 때마다 객체와 반대로 내 필드의 이름 배열. 이 코드를 복사하여 RF를 사용하는 다른 프로젝트에 붙여 넣기 때문에 이것이 내가 원하는 것을 나에게주는 것입니다 .props.fields. Part of me는 RF를 잘못 설정했다고 생각하지만 formReducer를 App.js로 가져 와서 내 다른 감속기와 결합했습니다.필드가 올바르게 ReduxForm을 사용하여 Props로 전달되지 않음
디버거를 쳤을 때 this.props.fields = [ 'query', 'numberOfResults']는 모든 것을 망가 뜨리고 있습니다. 여기
내 코드입니다 :이에 유래 내 첫 번째 질문은import _ from 'lodash';
import React, { Component, PropTypes } from 'react';
import { Field, reduxForm } from 'redux-form';
const FIELDS = {
query: {
type: 'input',
label: 'What are you looking for?'
},
numberOfResults: {
type: 'input',
label: 'Number of Results'
}
};
class YelpForm extends Component {
onSubmit(props) {
console.log('hey cutie')
}
renderField(fieldConfig, field) {
debugger
const fieldHelper = this.props.fields[field]
return (
<div className={`form-group ${fieldHelper.touched && fieldHelper.invalid ? 'has-danger' : '' }`} >
<label>{fieldConfig.label}</label>
<fieldConfig.type type="text" className="form-control" {...fieldHelper} />
<div className="text-help">
{fieldHelper.touched ? fieldHelper.error : ''}
</div>
</div>
);
}
render() {
const { handleSubmit } = this.props;
return (
<form onSubmit={handleSubmit(props => this.onSubmit(props))} >
{_.map(FIELDS, this.renderField.bind(this))}
<input type="submit">Submit</input>
</form>
);
}
}
function validate(values) {
const errors = {};
_.each(FIELDS, (type, field) => {
if (!values[field]) {
errors[field] = `Enter a ${field}`;
}
});
return errors;
}
export default reduxForm({
form: 'Yelp Form',
fields: _.keys(FIELDS),
validate
})(YelpForm);
입니다
; 사전에 도움을 주셔서 감사합니다!
어떤 이유로 ReduxForm을 다운 그레이드 할 때 작동하기 시작했습니다. 바라기를 이것은 누군가를 도울지도 모른다! – Lee
나는 똑같은 문제가 있었다. redux-form v6.0.2는 필드 이름 배열을 Component에 전달하고 v5.2.3은 작동했습니다 (필드가있는 객체로 전달됨). – user1491819