@insoutt/react-simple-form
TypeScript icon, indicating that this package has built-in type declarations

1.0.3 • Public • Published

react-simple-form

react-simple-form is a component to build Forms in react in a simple way.

Installation

Install react-simple-form with:

  npm install react-simple-form
  yarn add react-simple-form

Usage/Examples

import { FieldProps, Form } from "@insoutt/react-simple-form";
import {useState} from "react";


interface IForm {
    email: string
    password: string
}

function required(value: string | number) {
    return value.toString().length > 0 || 'Required field'
}

const formSchema: FieldProps<IForm>[] = [
    {
        name: 'email',
        type: 'email',
        label: 'E-mail',
        validation: required,
    },
    {
        name: 'password',
        type: 'password',
        label: 'Password',
        validation: required,
    },
];

function App() {
    const [isLoading, setIsLoading] = useState(false);

    const onSubmit = ({email, password}: IForm) => {
        // Submit logic
    }
    return (
        <Form<IForm>
            classNames={{
                submitButton: 'btn btn-secondary',
            }}
            hideClearButton
            isLoading={loading}
            onSubmit={onSubmit}
            fields={formSchema}
        />
    )
}

License

This project is licensed under the MIT license.

Package Sidebar

Install

npm i @insoutt/react-simple-form

Weekly Downloads

0

Version

1.0.3

License

MIT

Unpacked Size

89.6 kB

Total Files

74

Last publish

Collaborators

  • insoutt