string[] (a string being the field for which general error is to be shown)
customValidators
No
TFieldConfig
Usage
Set the validation state of a field using setFieldValue function.
Read the computed errors (if any) from the validtor using errors object.
//inside the Form componentimport{useValidationStore}from"@naukri-ui-dev/react-validator";constForm=()=>{const{
errors,//object to read errors
setFieldValue //function to set validator state}=useValidationStore();constonUsernameChange=(val: string)=>{//set the local state
...
//set the validator statesetFieldValue("username",val);}constonPasswordChange=(value: string)=>{//set the local state
...
//set the validator statesetFieldValue("password",value);}return(<form><div><inputonChange={(e)=>onUsernameChange(e.target.value)}placeholder="Username"/>{errors.username&&(<divclassName="err-msg">{errors.username}</div>)}</div><div><inputonChange={(e)=>onPasswordChange(e.target.value)}placeholder="Password"/>{errors.password&&(<divclassName="err-msg">{errors.password}</div>)}</div><buttontype="submit">
Submit
</button></form>);};
Demo
Clone the repo on your system
Open terminal and navigate to the cloned location
Do npm i and then npm start
You could see a demo form utilizing React Validator on localhost