Does redux-form field value can hold object instead of just a string?

后端 未结 5 1180
暖寄归人
暖寄归人 2020-12-31 18:10

Does redux-form field value can hold object instead of just a string?

Consider following example

    class SelectQuestions extends Component{
                


        
5条回答
  •  一个人的身影
    2020-12-31 18:21

    I think the better way to achieve that is to create two virtual fields selectedQuestionId and selectedQuestionName. Those fields are not to display. Then, each SelectQuestion can trigger a callback like:

    setSelectedQuestion = (event) => {
      var questionName = event.target.name; //or something like that
      var questionId = event.target.id; //or something like that
      this.props.fields.selectedQuestionName.onChange(questionName );
      this.props.fields.selectedQuestionId.onChange(questionId );
    }
    

    onChange can be called on redux-form fields to programmatically set the value.

提交回复
热议问题