redux-form-material-ui
redux-form-material-ui copied to clipboard
Cannot Dynamically Initialize Values (Need Default on Radio Buttons)
So I want to dynamically create radio buttons (the user adds a new page and a new radio field pops up). See this:
<Field name={`Radio${this.state.radioArray.length}button`} component={RadioButtonGroup} default="type1">
<RadioButton value="type1" label="All Code" onClick={()=>{this.setState({radioNum: 1})}}/>
<RadioButton value="type2" label="All Instructions" onClick={()=>{this.setState({radioNum: 2})}}/>
<RadioButton value="type3" label="Half and Half" onClick={()=>{this.setState({radioNum: 3})}}/>
</Field>
Now the problem is that name={"Radio${this.state.radioArray.length}button"}
is dynamic so in order to get a default value for this radio button I have to initialize some sort of dynamic initialValues object and pass it to redux. This would be poorly perfomant as I am assuming that this would then force each of the redux values to have to be re-initialized. However, even adding to an object the new name each time and passing it to the redux-form decorator, even with enableReinitialize: true
does not set the default values. The only "way" to get this to work is to pass a lot of Radio1button: "type1", Radio2button: "type2".... to the initializer.
I can either do this, or not have dynamic buttons, or have dynamic buttons with no initial values. Is there a way to fix this?