import { describe, bench } from "vitest";
import React from "react";
import { Field, Form } from "houseform";
import { cleanup, findByTestId, render } from "@testing-library/react";
import { Formik, Field as FormikField } from "formik";
import { FieldProps } from "formik/dist/Field";
import { Controller, useForm } from "react-hook-form";
const arr = Array.from({ length: 1000 }, (_, i) => i);
function HouseFormInitialRenderBenchmark() {
return (
);
}
function FormikInitialRenderBenchmark() {
return (
{}}
>
{() => (
<>
{arr.map((num, i) => (
{({ field }: FieldProps) => {
return (
);
}}
))}
>
)}
);
}
function ReactHookFormHeadlessInitialRenderBenchmark() {
const { control } = useForm({
defaultValues: {
num: arr,
},
});
return (
<>
{arr.map((num, i) => {
return (
(
)}
name={`num.${i}`}
/>
);
})}
>
);
}
function ReactHookFormInitialRenderBenchmark() {
const { register } = useForm({
defaultValues: {
num: arr,
},
});
return (
<>
{arr.map((num, i) => (
))}
>
);
}
describe("Renders 1,000 form items", () => {
bench(
"HouseForm",
async () => {
const { findByTestId } = render();
await findByTestId("999");
},
{
setup(task) {
task.opts.beforeEach = () => {
cleanup();
};
},
}
);
bench(
"Formik",
async () => {
const { findByTestId } = render();
await findByTestId("999");
},
{
setup(task) {
task.opts.beforeEach = () => {
cleanup();
};
},
}
);
bench(
"React Hook Form",
async () => {
const { findByTestId } = render();
await findByTestId("999");
},
{
setup(task) {
task.opts.beforeEach = () => {
cleanup();
};
},
}
);
bench(
"React Hook Form (Headless)",
async () => {
const { findByTestId } = render(
);
await findByTestId("999");
},
{
setup(task) {
task.opts.beforeEach = () => {
cleanup();
};
},
}
);
});