문제는 여기에 직접 redux-form
Field
구성 요소의 value
을 설정하려고하고 있지만 redux-form
의 전체 아이디어는 라이브러리가 알아서 할 수 있다는 것입니다.
당신이이
는 그냥 reduxForm
위의 REDUX connect
-decorator 스틱 (워드 프로세서에 "Initialize from state" 예 참조) 수행 할 initialValues
프로 프를 사용합니다 REDUX 형태 Field
의 초기 값을 설정하려면
- 데코레이터 및 redux 상태를 사용하여 초기 양식 값을 설정할 수 있습니다.
class MyForm extends Component {
render() {
return (
<form>
{ /* This one will have the static initial value */ }
<Field
name="staticValue"
component={ CustomComponent }
type="input"
placeholder="Static Placeholder"
/>
{ /* This one will have the dynamic initial value */ }
<Field
name="dynamicValue"
component={ CustomComponent }
type="input"
placeholder="Dynamic Placeholder"
/>
</form>
)
}
}
const mapStateToProps = reducers => {
return {
initialValues: {
staticValue: 'some static default initial value',
dynamicValue: reducers.dynamicReducer.dynamicValue
}
}
}
@connect(mapStateToProps)
@reduxForm({ formName: 'MyForm' })
class MyFormContainer extends Myform {}
희망이 있습니다.
입력 내용을 입력해도 로그에'undefined'가 출력됩니까? 귀하의 코드는 잘 보인다. –