vendredi 30 décembre 2016

Redux Form - Checkbox with a default value and set it to be disabled

I'd like to confirm if this structure is right.

I need to set default value for the checkbox, so I've used the checked={input.value}. I also need to set it to be disabled, then I've passed the disabled prop:

// Using the Checkbox component  
<Field
  name="completed"
  label="Completed"
  disabled={this.props.disableCompleted}
  component={Checkbox}
/>

function Checkbox({ input, label, disabled }) {
  return (
    <div className="form-group">
      <label className="mt-checkbox">
        <input 
          type="checkbox" 
          disabled={disabled} 
          checked={input.value} 
          {...input} /> {label}
        <span></span>
      </label>
    </div>
  );
}

Is there any better way to do this?




Aucun commentaire:

Enregistrer un commentaire