import { describe, bench } from "vitest"; import { Field, Form } from "houseform"; import { cleanup, findByTestId, fireEvent, render, } from "@testing-library/react"; import { Formik, FastField as FormikFastField } from "formik"; import { FieldProps } from "formik/dist/Field"; import { Controller, useForm } from "react-hook-form"; import React, { useState } from "react"; const arr = Array.from({ length: 1000 }, (_, i) => i); function HouseFormReRenderBenchmark() { const [count, setCount] = useState(0); return (

Count: {count}

{() => ( <> {arr.map((num, i) => { return ( memoChild={[]} key={i} name={`num[${i}]`} initialValue={num} > {({ value, onBlur, setValue }) => { return ( setValue(e.target.valueAsNumber)} /> ); }} ); })} )}
); } function FormikReRenderBenchmark() { const [count, setCount] = useState(0); return (

Count: {count}

{}} > {() => ( <> {arr.map((num, i) => ( {({ field }: FieldProps) => { return ( ); }} ))} )}
); } function ReactHookFormHeadlessReRenderBenchmark() { const [count, setCount] = useState(0); const { control } = useForm({ defaultValues: { num: arr, }, }); return (

Count: {count}

{arr.map((num, i) => { return ( ( )} name={`num.${i}`} /> ); })}
); } function ReactHookFormReRenderBenchmark() { const [count, setCount] = useState(0); const { register } = useForm({ defaultValues: { num: arr, }, }); return (

Count: {count}

{arr.map((num, i) => ( ))}
); } describe("Renders unrelated data in large forms", () => { bench( "HouseForm", async function (this) { const { findByTestId, findByText } = render( ); await findByTestId("999"); await findByText("Count: 0"); fireEvent.click(await findByText("Add")); await findByText("Count: 1"); await findByTestId("999"); }, { setup(task) { task.opts.beforeEach = () => { cleanup(); }; }, } ); bench( "Formik", async () => { const { findByTestId, findByText } = render(); await findByTestId("999"); await findByText("Count: 0"); fireEvent.click(await findByText("Add")); await findByText("Count: 1"); await findByTestId("999"); }, { setup(task) { task.opts.beforeEach = () => { cleanup(); }; }, } ); bench( "React Hook Form", async () => { const { findByTestId, findByText } = render( ); await findByTestId("999"); await findByText("Count: 0"); fireEvent.click(await findByText("Add")); await findByText("Count: 1"); await findByTestId("999"); }, { setup(task) { task.opts.beforeEach = () => { cleanup(); }; }, } ); bench( "React Hook Form (Headless)", async () => { const { findByTestId, findByText } = render( ); await findByTestId("999"); await findByText("Count: 0"); fireEvent.click(await findByText("Add")); await findByText("Count: 1"); await findByTestId("999"); }, { setup(task) { task.opts.beforeEach = () => { cleanup(); }; }, } ); });