UseForm hook
Useform hook: Custom react hook designed for advanced form management.
Offers access to the essential features of the Form component including: values, errors, touched fields, form utils & more.
UseForm is a specialized custom React hook designed for advanced form management, serving as the foundational core for the Form component. This hook comes in handy when you require greater control over your forms, offering access to essential objects such as values and errors. It's particularly valuable when you opt for alternative Field components that differ from FormFusion's default Input and Textarea components. With UseForm, you can tailor your form management to your specific needs, ensuring a flexible and adaptable solution for your web development projects.
Available parameters
#
|
#
|
#
|
#
|
Available configuration
The UseForm hook yields the entire form configuration, which you can use to tailor your form management precisely as desired. Here's an example of how to implement it:
const config = useForm({onSubmit: (values) => {console.log(values)}});
In the provided code snippet, the config
variable includes the following essential configuration parameters:
#
|
#
|
#
|
#
|
#
|
Example
import { Form, Input, useForm } from 'formfusion';
import './App.css';
const MyForm = () => {
const onSubmit = (data: object) => {
console.log('Success ' + JSON.stringify(data));
};
const config = useForm({ initialValues: { username: '' }, onSubmit });
return (
<Form config={config} className="form">
<Input
id="username"
name="username"
type="username"
label="Username"
required
/>
<button type="submit">Submit</button>
Your username is {config.values.username}
</Form>
);
};
export default MyForm;