npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

formgenie-react

v0.0.3

Published

<a name="top"></a>

Readme

formgenie-react is a library that helps you to generate forms in React. It is a simple and easy-to-use library that allows you to create forms with minimal code.

Installation

npm install formgenie-react zod

Usage

1. import the necessary modules

import React from 'react';
import { useFormBuilder, usseInput, type GetRef } from 'formgenie-react';
import { z } from 'zod';

2 Create Imput (optional)

import React from 'react';

export function InputTest(
    props: {
        tt: string // exemple of other props
        onChange: (value: string) => void // is use set value of input
        value: string, // is use get value of input
        errorMessage?: string  // is use get message error of zod schema
    }
) {
    return (
        <>
            <input
                type="text" 
                onChange={(event) => props.onChange(event.target.value)}
                value={props.value}
            />
            {props.errorMessage && <div>{props.errorMessage}</div>}
        </>
    );
}

[!NOTE] In this example, we have created a component InputTest which is a simple input. The component has the following properties:

  • tt: an arbitrary property
  • onChange: a function that takes the input value as a parameter
  • value: the value of the input
  • errorMessage: the error message from the zod schema validation (optional)

[!IMPORTANT] For a component to be usable by formgenie-react, it must have at least the following properties:

  • onChange: a function that takes the input value as a parameter
  • value: the value of the input
  • errorMessage: the error message from the zod schema validation (optional)

You can add other properties to your component, they will be definable in the form.

2. Create Form

import { useFormBuilder, useInput } from 'formgenie-react';
import { z } from 'zod';
import { InputTest } from './your/path/to/InputTest';

const Form = useFormBuilder({
    name: useInput(
        InputTest,
        {
            defaultValue: "test",
            zodSchema: z.coerce.number(),
            props: {
                tt: "rrr",
            }
        },
    ),
    prenom: useInput(
        InputTest,
        {
            defaultValue: "test",
            zodSchema: z.coerce.number(),
            props: {
                tt: "rrr"
            }
        },
    )
});

[!NOTE] In this example, we have created a form with two fields:

  • name: a field of type InputTest with the following properties:
    • defaultValue: the default value of the field
    • zodSchema: the validation schema of the field
    • props: additional properties of the field
  • prenom: a field of type InputTest with the following properties:
    • defaultValue: the default value of the field
    • zodSchema: the validation schema of the field
    • props: additional properties of the field

You can add as many fields as you want.
It is from the props that you can define the additional properties of your component.

3. Use Form

import React, { useRef } from 'react';
import type { GetRef } from 'formgenie-react';
import { Form } from './your/path/to/Form';

function TestForm() {

    const formRef = useRef<GetRef<typeof Form>>(null);
	
    const submit = async () => {
        if (formRef.current) {
            try {
                const result = await formRef.current.check();
                console.log(result);
			} catch (error) {
                console.error(error);
            }
        }
    };

    const reset = () => {
        if (formRef.current) {
            formRef.current.reset();
        }
};

    return (
        <>
            <Form ref={formRef} />
            <button onClick={submit}>Submit</button>
            <button onClick={reset}>Reset</button>
        </>
    );
}

[!NOTE] In this example, we have created a TestForm component that contains a Form. We have also created two functions:

  • submit: which is an example of form submission
  • reset: which is an example of form reset

To use a form created with formgenie-react, you need to give it a ref typed from the form.
For this, formgenie-react exports a GetRef type that allows you to retrieve the type of the form's ref.

[!IMPORTANT] To access the form values, you can do so through the form's ref.
The check function allows you to check if the form is valid and return the field values as an object.
The reset function allows you to reset the field values of the form. It does so based on the values set in the defaultValue of the fields.

4. Implement Form

import React from 'react';
import { TestForm } from './your/path/to/Form';

export function App() {
    return (
        <TestForm />
    );
}