This is how my project looks:
class ParentOfForm extends Component{
constructor(){this.state={initVals: null};}
componentDidMount(){
asyncCall.then((values) =>
setState({
initVals: {
initval1: valFromAsync,
..
}
})
);
}
render(){
const {initVals} = this.state;
{!initVals && <Form/>}
{!!initVals && <Form initialValues={initVals}/>}
}
}
----------------
class Form extends Component{
constructor(props){
super(props);
this.state = {
initval1: "",
..
}
}
render(){
return(
<form..>
..
</form>
);
}
}
Form = reduxForm({
form: "Form",
validate,
enableReinitialize: true
})(Form);
export default Form;
So as you can see, I'm trying to use values from an async function as initialValues to initialize the input fields of my form. When I define initialValues inside Form = reduxForm({...}) they get displayed correctly. However when I try to set them dynamically using the async call I can see the values being changed but they all seem to be undefined eventhough I can see them being filled in with console.log(). What am doing wrong?
Obvious alternatives I can't use because reasons: defaultValue, const Form = ().., no parent