Quick Start
To get started with Rapid Form, let’s create a simple form that collects user information.
-
Import the
useRapidForm
hook into your file:import { useRapidForm } from 'rapid-form'; -
Add
useRapidForm
hook to your component:export function MyComponent() {const { refValidation } = useRapidForm()// Your component code goes here} -
Add
refValidation
to your form:<formref={(ref) => {refValidation(ref)}}>{/* Your form fields go here */}</form> -
Add form required fields to your form:
<formref={(ref) => {refValidation(ref)}}><input type="text" required name="name" /><input type="email" required name="email" /><button type="submit">Submit</button></form> -
Show errors and disable the submit button based on form validation:
export function MyComponent() {const { refValidation, errors } = useRapidForm()const isValid = Object.keys(errors).lenght === 0return (<formref={(ref) => {refValidation(ref)}}><input type="text" required name="name" /><span>{errors.name}</span><input type="email" required name="email" /><span>{errors.email}</span><button type="submit" disabled={!isValid}>Submit</button></form>)}