react-simple-form is a component to build Forms in react in a simple way.
Install react-simple-form with:
npm install react-simple-form
yarn add react-simple-form
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}
/>
)
}
This project is licensed under the MIT license.