UNPKG

react-form-in-second

Version:
93 lines (72 loc) 1.5 kB
# React Form ## Getting Started Just add it and use ### Installing ``` npm i --save react-form-in-second ``` or ``` yarn add react-form-in-second ``` ### Usage ``` import Form, { Input, Select, Custom, Checkbox } from 'react-form-in-second' const Test = (props) => { const { error, onChange, getFormData, value } = props return <div>Hello from custom</div> } const App = () => { const onSubmit = () => { } return ( <Form title="Form Title" className="" onSubmit={onSubmit}> <Input label="User name:" name="name" validator={(value, formData) => { console.log(value, formData) return false }} errMsg="Error message for validation" /> <Checkbox name="gender" label="Male" value={true} validator={(value, formData) => { console.log(value, formData) }} errMsg="Error message for validation" /> <Select label="test" name="fruit" multiple options={[ {value: 1, label: 'apple'}, {value: 2, label: 'banana'}, {value: 4, label: 'others', children: [ {value: 3, label: 'mango'}, ]}, ]} validator={(value, formData) => { console.log(value, formData) }} errMsg="Error message for validation" /> <Custom component={Test} /> <div> <button type="submit" name="submit">Submit</button> </div> </Form> ) } ``` ### for Development 1. "npm i" or "yarn" 2. npm run local 3. open [http://localhost:3000](http://localhost:3000)