You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importvalidatorfrom'validator';constrequired=(value)=>{if(!value.toString().trim().length){// We can return string or jsx as the 'error' prop for the validated Componentreturn'require';}};constemail=(value)=>{if(!validator.isEmail(value)){return`${value} is not a valid email.`}};constlt=(value,props)=>{// get the maxLength from component's propsif(value.toString().trim().length>props.maxLength){// Return jsxreturn<spanclassName="error">The value exceeded {props.maxLength} symbols.</span>}};constpassword=(value,props,components)=>{// NOTE: Tricky place. The 'value' argument is always current component's value.// So in case we're 'changing' let's say 'password' component - we'll compare it's value with 'confirm' value.// But if we're changing 'confirm' component - the condition will always be true// If we need to always compare own values - replace 'value' with components.password[0].value and make some magic with error rendering.if(value!==components['confirm'][0].value){// components['password'][0].value !== components['confirm'][0].value// 'confirm' - name of input// components['confirm'] - array of same-name components because of checkboxes and radiosreturn<spanclassName="error">Passwords are not equal.</span>}};