Skip to content

Instantly share code, notes, and snippets.

@alexwhin
Last active February 8, 2020 11:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexwhin/4209a8e4aa7d60a61818c0a307b6be19 to your computer and use it in GitHub Desktop.
Save alexwhin/4209a8e4aa7d60a61818c0a307b6be19 to your computer and use it in GitHub Desktop.
Checkbox component for Formik (https://github.com/jaredpalmer/formik)
import React from "react";
import { Field, FieldProps } from "formik";
interface Props {
id: string;
name: string;
className: string;
}
export const Checkbox = ({ id, name, className }: Props): JSX.Element => (
<Field
name={name}
render={({ field }: FieldProps) => (
<input
id={id}
{...field}
type="checkbox"
className={className}
checked={field.value}
/>
)}
/>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment