reactackle icon indicating copy to clipboard operation
reactackle copied to clipboard

reactackle-checkbox calls props.onChange with object {value: checked}

Open agraver opened this issue 7 years ago • 1 comments

I am using reactackle-checkbox in combination with mobx-react-form.

Mobx-react-form magically binds its own onChange handler to the inputs. It expects the parameter to be just the value of the input. i.e. onChange (value) { .... }

In case of reactackle checkbox it calls the function with an object {value: checked}. This leads to inconvenience in handling the form, since we have to add an extra line of code for each checkbox to read its value.

Is there a reason that props.onChange is called with an object? Is it possible to add a change to improve this in the next major release?

https://github.com/bcrumbs/reactackle/blob/master/packages/reactackle-checkbox/src/Checkbox.js#L108-L118

  _changeCheckedState(checked) {
    if (isUndef(this.props.checked)) {
      this.setState({
        checked,
      });
    }

    this.props.onChange({
      value: checked,
    });
  }

agraver avatar Jul 02 '18 12:07 agraver

@agraver Hey, Anton. Input components were designed to work with Booben(https://github.com/bcrumbs/booben) constructor. It may be improved in the next big release.

VNadygin avatar Jul 02 '18 18:07 VNadygin