@insoutt/react-simple-form
v1.0.3
Published
Build react dynamic forms using JSON format
Downloads
3
Maintainers
Readme
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.