DEV Community

Discussion on: How to implement a working checkbox component in Formik 1.5.8

Collapse
 
alexwhin profile image
Alex Whinfield

Working great thank you, I'm using it with TypeScript so here is my component for anybody that may be interested.

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}
      />
    )}
  />
);