1.0.2 • Published 2 years ago
target-form-state v1.0.2
npm install target-form-state
In the project directory:
You can use this hook as a form object which can keep track all the properties of the object. Each property can change the value to (true or false) depending on the state of form. For instance..
MODEL
export interface City { cityId?: string; name: string; active: boolean; createdAt?: Date; updatedAt?: Date; }
REACT COMPONENT
const cityForm, setCityForm = useState({ cityId: "", name: "", active: true, });
USING TARGET-FORM-STATE
const cityFormState, setCityFormState, reset = useFormState(cityForm);
SETTING VALIDATION
setCityFormState((prev) => ({ ...prev, e.target.name: true }));
RESETTING THE STATE OF FORM
reset(cityForm);
Learn More
You can learn more in the Create React App documentation.
To learn React, check out the React documentation.