Skip to content

Instantly share code, notes, and snippets.

View joshferrell's full-sized avatar

Joshua Ferrell joshferrell

View GitHub Profile
@sibelius
sibelius / useFastField.tsx
Last active May 10, 2023 04:07
useFastField that uses local state `onChange` and sync back to formik only `onBlur`
import React, { useState, useEffect } from 'react';
import { useField, FieldHookConfig, FieldInputProps, FieldMetaProps, FieldHelperProps } from 'formik';
import { useDebouncedCallback } from 'use-debounce';
const DEBOUNCE_DELAY = 300;
export function useFastField<Val = any>(
propsOrFieldName: string | FieldHookConfig<Val>,
): [FieldInputProps<Val>, FieldMetaProps<Val>, FieldHelperProps<Val>] {
const [field, meta, helpers] = useField<Val>(propsOrFieldName);