简体   繁体   中英

Redux form - own value in Field with type radio

I want to put some text in to the radio field (with Redux form).

I have fields like this:

<Field
  name={some.name1}
  value={'text1'}
  component={renderRadioElement}
  type="radio"
/>

<Field
  name={some.name2}
  value={'text2'}
  component={renderRadioElement}
  type="radio"
/>

...

Everything works correctly until the first value change .

If I want to change the value several times: state -> form -> ... -> values -> some does not update values.

My question is - how to correctly enter a text value into a radio field?

If I understood correctly your comment you have a value on your component state where youve decleared the form and you wnat to pass in that value to your field. If thats it what you want to do is dispatch the value to the redux-form store. To do that in your class you are receiving a prop which is change. injected by redux-form. what you want to do is use that function to set the value

const { change } = this.props;
change('some.name2', this.state.yourValue)

hope it helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM