dispatch/client/src/js/components/ui/Checkbox.js

30 lines
636 B
JavaScript
Raw Normal View History

2018-05-16 03:02:48 +00:00
import React from 'react';
import { Field } from 'formik';
const Checkbox = ({ name, label, onChange, ...props }) => (
<Field
name={name}
render={({ field, form }) => (
<label htmlFor={name}>
{label && <div>{label}</div>}
<input
type="checkbox"
id={name}
name={name}
checked={field.value}
onChange={e => {
form.setFieldTouched(name, true);
field.onChange(e);
if (onChange) {
onChange(e);
}
}}
{...props}
/>
</label>
)}
/>
);
export default Checkbox;