{"id":65879,"date":"2019-05-24T04:21:10","date_gmt":"2019-05-24T11:21:10","guid":{"rendered":"http:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/"},"modified":"2019-05-24T04:21:10","modified_gmt":"2019-05-24T11:21:10","slug":"creating-your-own-react-validation-library-the-features-part-2","status":"publish","type":"post","link":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/","title":{"rendered":"Creating Your Own React Validation Library: The Features (Part 2)"},"content":{"rendered":"<link rel=\"canonical\" href=\"https:\/\/www.smashingmagazine.com\/2019\/05\/react-validation-library-features-part2\/\"><title>Creating Your Own React Validation Library: The Features (Part 2)<\/title><\/p>\n<article>\n<header>\n<h1>Creating Your Own React Validation Library: The Features (Part 2)<\/h1>\n<address>Kristofer Selbekk<\/address>\n<p>                  <time datetime=\"2019-05-23T13:00:16+02:00\">2019-05-23T13:00:16+02:00<\/time><time datetime=\"2019-05-24T11:09:32+00:00\">2019-05-24T11:09:32+00:00<\/time><\/header>\n<p>Implementing a validation library isn\u2019t all that hard. Neither is adding all of those extra features that make <em>your<\/em> validation library much better than the rest.<\/p>\n<p>This article will continue implementing the validation library we started implementing in the <a href=\"https:\/\/www.smashingmagazine.com\/2019\/05\/react-validation-library-basics-part1\/\">previous part<\/a> of this article series. These are the features that are going to take us from a simple proof of concept to an actual usable library!<\/p>\n<ul>\n<li>Part 1: <a href=\"https:\/\/www.smashingmagazine.com\/2019\/05\/react-validation-library-basics-part1\/\">The Basics<\/a><\/li>\n<li><strong>Part 2: The Features<\/strong><\/li>\n<li>Part 3: The Experience (Coming up next week)<\/li>\n<\/ul>\n<h3>Only Show Validation On Submit<\/h3>\n<p>Since we\u2019re validating on all change events, we\u2019re showing the user error messages way too early for a good user experience. There are a few ways we can mitigate this.<\/p>\n<p>The first solution is simply providing the <code>submitted<\/code> flag as a returned property of the <code>useValidation<\/code> hook. This way, we can check whether or not the form is submitted before showing an error message. The downside here is that our \u201cshow error code\u201d gets a bit longer:<\/p>\n<pre><code><label>\n  Username\n  <br \/>\n  <input {...getFieldProps('username')} \/>\n  {submitted && errors.username && (\n    <div className=\"error\">{errors.username}<\/div>\n  )}\n<\/label>\n<\/code><\/pre>\n<p>Another approach is to provide a second set of errors (let\u2019s call them <code>submittedErrors<\/code>), which is an empty object if <code>submitted<\/code> is false, and the <code>errors<\/code> object if it\u2019s true. We can implement it like this:<\/p>\n<pre><code>const useValidation = config => {\n  \/\/ as before\n  return {\n    errors: state.errors,\n    submittedErrors: state.submitted ? state.errors : {},\n  };\n}\n<\/code><\/pre>\n<p>This way, we can simply destructure out the type of errors that we want to show. We could, of course, do this at the call site as well \u2014 but by providing it here, we\u2019re implementing it once instead of inside all consumers.<\/p>\n<ul>\n<li><a href=\"https:\/\/codesandbox.io\/embed\/k951np8915?fontsize=14\">See CodeSandbox demo<\/a> showing how <code>submittedErrors<\/code> can be used.<\/li>\n<\/ul>\n<div data-component=\"FeaturePanel\" data-audience=\"non-subscriber\" data-remove=\"true\"><\/div>\n<h3>Show Error Messages On-Blur<\/h3>\n<p>A lot of people want to be shown an error once they leave a certain field. We can add support for this, by tracking which fields have been \u201cblurred\u201d (navigated away from), and returning an object <code>blurredErrors<\/code>, similar to the <code>submittedErrors<\/code> above.<\/p>\n<p>The implementation requires us to handle a new action type \u2014 <code>blur<\/code>, which will be updating a new state object called <code>blurred<\/code>:<\/p>\n<pre><code>const initialState = {\n  values: {},\n  errors: {},\n  blurred: {},\n  submitted: false,\n};\n\nfunction validationReducer(state, action) {\n  switch (action.type) {\n    \/\/ as before\n    case 'blur':\n      const blurred = { \n        ...state.blurred, \n        [action.payload]: true \n      }; \n      return { ...state, blurred };\n    default:\n      throw new Error('Unknown action type');\n  }\n}\n<\/code><\/pre>\n<p>When we dispatch the <code>blur<\/code> action, we create a new property in the <code>blurred<\/code> state object with the field name as a key, indicating that <em>that<\/em> field has been blurred.<\/p>\n<p>The next step is adding an <code>onBlur<\/code> prop to our <code>getFieldProps<\/code> function, that dispatches this action when applicable:<\/p>\n<pre><code>getFieldProps: fieldName => ({\n  \/\/ as before\n  onBlur: () => {\n    dispatch({ type: 'blur', payload: fieldName });\n  },\n}),\n<\/code><\/pre>\n<p>Finally, we need to provide the <code>blurredErrors<\/code> from our <code>useValidation<\/code> hook so that we can show the errors only when needed.<\/p>\n<div>\n<pre><code>const blurredErrors = useMemo(() => {\n    const returnValue = {};\n    for (let fieldName in state.errors) {\n      returnValue[fieldName] = state.blurred[fieldName]\n        ? state.errors[fieldName]\n        : null;\n    }\n    return returnValue;\n  }, [state.errors, state.blurred]);\nreturn {\n  \/\/ as before\n  blurredErrors,\n};\n<\/code><\/pre>\n<\/div>\n<p>Here, we create a <a href=\"https:\/\/en.wikipedia.org\/wiki\/Memoization\">memoized function<\/a> that figures out which errors to show based on whether or not the field has been blurred. We recalculate this set of errors whenever the errors or blurred objects change. You can read more about the <code>useMemo<\/code> hook in the <a href=\"https:\/\/reactjs.org\/docs\/hooks-reference.html#usememo\">documentation<\/a>.<\/p>\n<ul>\n<li><a href=\"https:\/\/codesandbox.io\/embed\/6zm3zj9qlk?fontsize=14\">See CodeSandbox demo<\/a><\/li>\n<\/ul>\n<h3>Time For A Tiny Refactor<\/h3>\n<p>Our <code>useValidation<\/code> component is now returning three sets of errors \u2014 most of which will look the same at some point in time. Instead of going down this route, we\u2019re going to let the user specify in the config when they want the errors in their form to show up.<\/p>\n<p>Our new option \u2014 <code>showErrors<\/code> \u2014 will accept either \u201csubmit\u201d (the default), \u201calways\u201d or \u201cblur\u201d. We can add more options later, if we need to.<\/p>\n<div>\n<pre><code>function getErrors(state, config) {\n  if (config.showErrors === 'always') {\n    return state.errors;\n  }\n  if (config.showErrors === 'blur') {\n    return Object.entries(state.blurred)\n      .filter(([, blurred]) => blurred)\n      .reduce((acc, [name]) => ({ ...acc, [name]: state.errors[name] }), {});\n  }\n  return state.submitted ? state.errors : {};\n}\nconst useValidation = config => {\n  \/\/ as before\n  const errors = useMemo(\n    () => getErrors(state, config), \n    [state, config]\n  );\n\n  return {\n    errors,\n    \/\/ as before\n  };\n};\n<\/code><\/pre>\n<\/div>\n<p>Since the error handling code started to take most of our space, we\u2019re refactoring it out into its own function. If you don\u2019t follow the <code>Object.entries<\/code> and <code>.reduce<\/code> stuff \u2014 that\u2019s fine \u2014 it\u2019s a rewrite of the <code>for...in<\/code> code in the last section.<\/p>\n<p>If we required onBlur or instant validation, we could specify the <code>showError<\/code> prop in our <code>useValidation<\/code> configuration object.<\/p>\n<div>\n<pre><code>const config = {\n  \/\/ as before\n  showErrors: 'blur',\n};\nconst { getFormProps, getFieldProps, errors } = useValidation(config);\n\/\/ errors would now only include the ones that have been blurred\n<\/code><\/pre>\n<\/div>\n<ul>\n<li><a href=\"https:\/\/codesandbox.io\/embed\/w216oz1x2w?fontsize=14\">See CodeSandbox demo<\/a><\/li>\n<\/ul>\n<h5>Note On Assumptions<\/h5>\n<blockquote><p>\u201cNote that I&#8217;m now assuming that each form will want to show errors the same way (always on submit, always on blur, etc). That might be true for most applications, but probably not for all. Being aware of your assumptions is a <strong>huge<\/strong> part of creating your API.\u201d<\/p><\/blockquote>\n<div><\/div>\n<h3>Allow For Cross-Validation<\/h3>\n<p>A really powerful feature of a validation library is to allow for cross-validation \u2014 that is, to base one field\u2019s validation on another field\u2019s value.<\/p>\n<p>To allow this, we need to make our custom hook accept a function instead of an object. This function will be called with the current field values. Implementing it is actually only three lines of code!<\/p>\n<pre><code>function useValidation(config) {\n  const [state, dispatch] = useReducer(...);\n  if (typeof config === 'function') {\n    config = config(state.values);\n  }\n}\n<\/code><\/pre>\n<p>To use this feature, we can simply pass a function that returns the configuration object to <code>useValidation<\/code>:<\/p>\n<div>\n<pre><code>const { getFieldProps } = useValidation(fields => ({ \n  password: {\n    isRequired: { message: 'Please fill out the password' },\n  },\n  repeatPassword: {\n    isRequired: { message: 'Please fill out the password one more time' },\n    isEqual: { value: fields.password, message: 'Your passwords don\u2019t match' }\n  }\n}));\n<\/code><\/pre>\n<\/div>\n<p>Here, we use the value of <code>fields.password<\/code> to make sure two password fields contain the same input (which is terrible user experience, but that\u2019s for another blog post).<\/p>\n<ul>\n<li><a href=\"https:\/\/codesandbox.io\/embed\/0x5pomny3n?fontsize=14\">See CodeSandbox demo<\/a> that doesn\u2019t let the username and the password be the same value.<\/li>\n<\/ul>\n<h3>Add Some Accessibility Wins<\/h3>\n<p>A neat thing to do when you\u2019re in charge of the props of a field is to add the correct aria-tags by default. This will help screen readers with explaining your form.<\/p>\n<p>A very simple improvement is to add <code>aria-invalid=\"true\"<\/code> if the field has an error. Let\u2019s implement that:<\/p>\n<pre><code>const useValidation = config => {\n  \/\/ as before\n  return {\n    \/\/ as before\n    getFieldProps: fieldName => ({\n      \/\/ as before\n      'aria-invalid': String(!!errors[fieldName]),\n    }),\n  }\n};\n<\/code><\/pre>\n<p>That\u2019s <em>one<\/em> added line of code, and a <strong>much<\/strong> better user experience for screen reader users.<\/p>\n<p>You might wonder about why we write <code>String(!!state.errors[fieldName])<\/code>? <code>state.errors[fieldName]<\/code> is a string, and the double negation operator gives us a boolean (and not just a truthy or falsy value). However, the <code>aria-invalid<\/code> property should be a string (it can also read \u201cgrammar\u201d or \u201cspelling\u201d, in addition to \u201ctrue\u201d or \u201cfalse\u201d), so we need to coerce that boolean into its string equivalent.<\/p>\n<p>There are still a few more tweaks we could do to improve accessibility, but this seems like a fair start.<\/p>\n<div><\/div>\n<h4>Shorthand Validation Message Syntax<\/h4>\n<p>Most of the validators in the <code>calidators<\/code> package (and most other validators, I assume) only require an error message. Wouldn\u2019t it be nice if we could just pass that string instead of an object with a <code>message<\/code> property containing that string?<\/p>\n<p>Let\u2019s implement that in our <code>validateField<\/code> function:<\/p>\n<div>\n<pre><code>function validateField(fieldValue = '', fieldConfig, allFieldValues) {\n  for (let validatorName in fieldConfig) {\n    let validatorConfig = fieldConfig[validatorName];\n    if (typeof validatorConfig === \u2019string') {\n      validatorConfig = { message: validatorConfig };\n    }\n    const configuredValidator = validators[validatorName](validatorConfig);\n    const errorMessage = configuredValidator(fieldValue);\n\n    if (errorMessage) {\n      return errorMessage;\n    }\n  }\n  return null;\n}\n<\/code><\/pre>\n<\/div>\n<p>This way, we can rewrite our validation config like so:<\/p>\n<pre><code>const config = {\n  username: {\n    isRequired: 'The username is required',\n    isEmail: 'The username should be a valid email address',\n  },\n};\n<\/code><\/pre>\n<p>Much cleaner!<\/p>\n<h3>Initial Field Values<\/h3>\n<p>Sometimes, we need to validate a form that\u2019s already filled out. Our custom hook doesn\u2019t support that yet \u2014 so let\u2019s get to it!<\/p>\n<p>Initial field values will be specified in the config for each field, in the property <code>initialValue<\/code>. If it\u2019s not specified, it defaults to an empty string.<\/p>\n<p>We\u2019re going to create a function <code>getInitialState<\/code>, which will create the initial state of our reducer for us.<\/p>\n<div>\n<pre><code>function getInitialState(config) {\n  if (typeof config === 'function') {\n    config = config({});\n  }\n  const initialValues = {};\n  const initialBlurred = {};\n  for (let fieldName in config.fields) {\n    initialValues[fieldName] = config.fields[fieldName].initialValue || '';\n    initialBlurred[fieldName] = false;\n  }\n  const initialErrors = validateFields(initialValues, config.fields);\n  return {\n    values: initialValues,\n    errors: initialErrors,\n    blurred: initialBlurred,\n    submitted: false,\n  };\n}\n<\/code><\/pre>\n<\/div>\n<p>We go through all fields, check if they have an <code>initialValue<\/code> property, and set the initial value accordingly. Then we run those initial values through the validators and calculate the initial errors as well. We return the initial state object, which can then be passed to our <code>useReducer<\/code> hook.<\/p>\n<p>Since we\u2019re introducing a non-validator prop into the fields config, we need to skip it when we validate our fields. To do that, we change our <code>validateField<\/code> function:<\/p>\n<pre><code>function validateField(fieldValue = '', fieldConfig) {\n  const specialProps = ['initialValue'];\n  for (let validatorName in fieldConfig) {\n    if (specialProps.includes(validatorName)) {\n      continue;\n    }\n    \/\/ as before\n  }\n}\n<\/code><\/pre>\n<p>As we keep on adding more features like this, we can add them to our <code>specialProps<\/code> array.<\/p>\n<ul>\n<li><a href=\"https:\/\/codesandbox.io\/embed\/kor9r1v7yv?fontsize=14\">See CodeSandbox demo<\/a><\/li>\n<\/ul>\n<h3>Summing Up<\/h3>\n<p>We\u2019re well on our way to create an amazing validation library. We\u2019ve added tons of features, and we\u2019re pretty much-thought leaders by now.<\/p>\n<p>In the next part of this series, we\u2019re going to add all of those extras that make our validation library even trend on LinkedIn. Stay tuned!<\/p>\n<div>\n  <img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.taterboy.com\/blog\/wp-content\/uploads\/2019\/05\/logo-red-17.png?w=900\" alt=\"Smashing Editorial\"><span>(dm, yk, il)<\/span>\n<\/div>\n<\/article>\n<p class=\"wpematico_credit\"><small>Powered by <a href=\"http:\/\/www.wpematico.com\" target=\"_blank\">WPeMatico<\/a><\/small><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Creating Your Own React Validation Library: The Features (Part 2) Creating Your Own React Validation Library: The Features (Part 2) Kristofer Selbekk 2019-05-23T13:00:16+02:002019-05-24T11:09:32+00:00 Implementing a validation library isn\u2019t all that hard. Neither is adding all of those extra features that make your validation library much better than the rest. This article will continue implementing the&#8230;<a class=\"moretag\" href=\"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/\"> Read the full article&#8230;<\/a><\/p>\n","protected":false},"author":4,"featured_media":65880,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[371],"tags":[],"class_list":["post-65879","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-user-experience"],"aioseo_notices":[],"aioseo_head":"\n\t\t<!-- All in One SEO 5.0.0.1 - aioseo.com -->\n\t<meta name=\"description\" content=\"Creating Your Own React Validation Library: The Features (Part 2)Creating Your Own React Validation Library: The Features (Part 2) Kristofer Selbekk 2019-05-23T13:00:16+02:002019-05-24T11:09:32+00:00Implementing a validation library isn\u2019t all that hard. Neither is adding all of those extra features that make your validation library much better than the rest. This article will continue implementing the validation library\" \/>\n\t<meta name=\"robots\" content=\"max-image-preview:large\" \/>\n\t<meta name=\"author\" content=\"Guest Contribution\"\/>\n\t<meta name=\"keywords\" content=\"user experience\" \/>\n\t<link rel=\"canonical\" href=\"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/\" \/>\n\t<meta name=\"generator\" content=\"All in One SEO (AIOSEO) 5.0.0.1\" \/>\n\t\t<meta property=\"og:locale\" content=\"en_US\" \/>\n\t\t<meta property=\"og:site_name\" content=\"Design for Immersive Technologies | User Experience for Games, Virtual Reality (VR) and Augmented\/Mixed Reality (AR\/MR)\" \/>\n\t\t<meta property=\"og:type\" content=\"article\" \/>\n\t\t<meta property=\"og:title\" content=\"Creating Your Own React Validation Library: The Features (Part 2) | Design for Immersive Technologies\" \/>\n\t\t<meta property=\"og:description\" content=\"Creating Your Own React Validation Library: The Features (Part 2)Creating Your Own React Validation Library: The Features (Part 2) Kristofer Selbekk 2019-05-23T13:00:16+02:002019-05-24T11:09:32+00:00Implementing a validation library isn\u2019t all that hard. Neither is adding all of those extra features that make your validation library much better than the rest. This article will continue implementing the validation library\" \/>\n\t\t<meta property=\"og:url\" content=\"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/\" \/>\n\t\t<meta property=\"article:published_time\" content=\"2019-05-24T11:21:10+00:00\" \/>\n\t\t<meta property=\"article:modified_time\" content=\"2019-05-24T11:21:10+00:00\" \/>\n\t\t<meta name=\"twitter:card\" content=\"summary\" \/>\n\t\t<meta name=\"twitter:title\" content=\"Creating Your Own React Validation Library: The Features (Part 2) | Design for Immersive Technologies\" \/>\n\t\t<meta name=\"twitter:description\" content=\"Creating Your Own React Validation Library: The Features (Part 2)Creating Your Own React Validation Library: The Features (Part 2) Kristofer Selbekk 2019-05-23T13:00:16+02:002019-05-24T11:09:32+00:00Implementing a validation library isn\u2019t all that hard. Neither is adding all of those extra features that make your validation library much better than the rest. This article will continue implementing the validation library\" \/>\n\t\t<script type=\"application\/ld+json\" class=\"aioseo-schema\">\n\t\t\t{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#article\",\"name\":\"Creating Your Own React Validation Library: The Features (Part 2) | Design for Immersive Technologies\",\"headline\":\"Creating Your Own React Validation Library: The Features (Part 2)\",\"author\":{\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/author\\\/guestcontribution\\\/#author\"},\"publisher\":{\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/#organization\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.taterboy.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/logo-red-17.png?fit=60%2C80&ssl=1\",\"width\":60,\"height\":80},\"datePublished\":\"2019-05-24T04:21:10-07:00\",\"dateModified\":\"2019-05-24T04:21:10-07:00\",\"inLanguage\":\"en-US\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#webpage\"},\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#webpage\"},\"articleSection\":\"User Experience\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#breadcrumblist\",\"itemListElement\":[{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog#listItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.taterboy.com\\\/blog\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/category\\\/user-experience\\\/#listItem\",\"name\":\"User Experience\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/category\\\/user-experience\\\/#listItem\",\"position\":2,\"name\":\"User Experience\",\"item\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/category\\\/user-experience\\\/\",\"nextItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#listItem\",\"name\":\"Creating Your Own React Validation Library: The Features (Part 2)\"},\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog#listItem\",\"name\":\"Home\"}},{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#listItem\",\"position\":3,\"name\":\"Creating Your Own React Validation Library: The Features (Part 2)\",\"previousItem\":{\"@type\":\"ListItem\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/category\\\/user-experience\\\/#listItem\",\"name\":\"User Experience\"}}]},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/#organization\",\"name\":\"Design for Immersive Technologies\",\"description\":\"User Experience for Games, Virtual Reality (VR) and Augmented\\\/Mixed Reality (AR\\\/MR)\",\"url\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/author\\\/guestcontribution\\\/#author\",\"url\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/author\\\/guestcontribution\\\/\",\"name\":\"Guest Contribution\",\"image\":{\"@type\":\"ImageObject\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#authorImage\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/d2aad73eb0f48c67b141e9fc978a0e498969791ed623346e361d02d19775b0bb?s=96&d=mm&r=g\",\"width\":96,\"height\":96,\"caption\":\"Guest Contribution\"}},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#webpage\",\"url\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/\",\"name\":\"Creating Your Own React Validation Library: The Features (Part 2) | Design for Immersive Technologies\",\"description\":\"Creating Your Own React Validation Library: The Features (Part 2)Creating Your Own React Validation Library: The Features (Part 2) Kristofer Selbekk 2019-05-23T13:00:16+02:002019-05-24T11:09:32+00:00Implementing a validation library isn\\u2019t all that hard. Neither is adding all of those extra features that make your validation library much better than the rest. This article will continue implementing the validation library\",\"inLanguage\":\"en-US\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/#website\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#breadcrumblist\"},\"author\":{\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/author\\\/guestcontribution\\\/#author\"},\"creator\":{\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/author\\\/guestcontribution\\\/#author\"},\"image\":{\"@type\":\"ImageObject\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/www.taterboy.com\\\/blog\\\/wp-content\\\/uploads\\\/2019\\\/05\\\/logo-red-17.png?fit=60%2C80&ssl=1\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#mainImage\",\"width\":60,\"height\":80},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/2019\\\/05\\\/creating-your-own-react-validation-library-the-features-part-2\\\/#mainImage\"},\"datePublished\":\"2019-05-24T04:21:10-07:00\",\"dateModified\":\"2019-05-24T04:21:10-07:00\"},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/\",\"name\":\"Design for Immersive Technologies\",\"description\":\"User Experience for Games, Virtual Reality (VR) and Augmented\\\/Mixed Reality (AR\\\/MR)\",\"inLanguage\":\"en-US\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.taterboy.com\\\/blog\\\/#organization\"}}]}\n\t\t<\/script>\n\t\t<!-- All in One SEO -->\n\n","aioseo_head_json":{"title":"Creating Your Own React Validation Library: The Features (Part 2) | Design for Immersive Technologies","description":"Creating Your Own React Validation Library: The Features (Part 2)Creating Your Own React Validation Library: The Features (Part 2) Kristofer Selbekk 2019-05-23T13:00:16+02:002019-05-24T11:09:32+00:00Implementing a validation library isn\u2019t all that hard. Neither is adding all of those extra features that make your validation library much better than the rest. This article will continue implementing the validation library","canonical_url":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/","robots":"max-image-preview:large","keywords":"user experience","webmasterTools":{"miscellaneous":""},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#article","name":"Creating Your Own React Validation Library: The Features (Part 2) | Design for Immersive Technologies","headline":"Creating Your Own React Validation Library: The Features (Part 2)","author":{"@id":"https:\/\/www.taterboy.com\/blog\/author\/guestcontribution\/#author"},"publisher":{"@id":"https:\/\/www.taterboy.com\/blog\/#organization"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/www.taterboy.com\/blog\/wp-content\/uploads\/2019\/05\/logo-red-17.png?fit=60%2C80&ssl=1","width":60,"height":80},"datePublished":"2019-05-24T04:21:10-07:00","dateModified":"2019-05-24T04:21:10-07:00","inLanguage":"en-US","mainEntityOfPage":{"@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#webpage"},"isPartOf":{"@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#webpage"},"articleSection":"User Experience"},{"@type":"BreadcrumbList","@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#breadcrumblist","itemListElement":[{"@type":"ListItem","@id":"https:\/\/www.taterboy.com\/blog#listItem","position":1,"name":"Home","item":"https:\/\/www.taterboy.com\/blog","nextItem":{"@type":"ListItem","@id":"https:\/\/www.taterboy.com\/blog\/category\/user-experience\/#listItem","name":"User Experience"}},{"@type":"ListItem","@id":"https:\/\/www.taterboy.com\/blog\/category\/user-experience\/#listItem","position":2,"name":"User Experience","item":"https:\/\/www.taterboy.com\/blog\/category\/user-experience\/","nextItem":{"@type":"ListItem","@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#listItem","name":"Creating Your Own React Validation Library: The Features (Part 2)"},"previousItem":{"@type":"ListItem","@id":"https:\/\/www.taterboy.com\/blog#listItem","name":"Home"}},{"@type":"ListItem","@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#listItem","position":3,"name":"Creating Your Own React Validation Library: The Features (Part 2)","previousItem":{"@type":"ListItem","@id":"https:\/\/www.taterboy.com\/blog\/category\/user-experience\/#listItem","name":"User Experience"}}]},{"@type":"Organization","@id":"https:\/\/www.taterboy.com\/blog\/#organization","name":"Design for Immersive Technologies","description":"User Experience for Games, Virtual Reality (VR) and Augmented\/Mixed Reality (AR\/MR)","url":"https:\/\/www.taterboy.com\/blog\/"},{"@type":"Person","@id":"https:\/\/www.taterboy.com\/blog\/author\/guestcontribution\/#author","url":"https:\/\/www.taterboy.com\/blog\/author\/guestcontribution\/","name":"Guest Contribution","image":{"@type":"ImageObject","@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#authorImage","url":"https:\/\/secure.gravatar.com\/avatar\/d2aad73eb0f48c67b141e9fc978a0e498969791ed623346e361d02d19775b0bb?s=96&d=mm&r=g","width":96,"height":96,"caption":"Guest Contribution"}},{"@type":"WebPage","@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#webpage","url":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/","name":"Creating Your Own React Validation Library: The Features (Part 2) | Design for Immersive Technologies","description":"Creating Your Own React Validation Library: The Features (Part 2)Creating Your Own React Validation Library: The Features (Part 2) Kristofer Selbekk 2019-05-23T13:00:16+02:002019-05-24T11:09:32+00:00Implementing a validation library isn\u2019t all that hard. Neither is adding all of those extra features that make your validation library much better than the rest. This article will continue implementing the validation library","inLanguage":"en-US","isPartOf":{"@id":"https:\/\/www.taterboy.com\/blog\/#website"},"breadcrumb":{"@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#breadcrumblist"},"author":{"@id":"https:\/\/www.taterboy.com\/blog\/author\/guestcontribution\/#author"},"creator":{"@id":"https:\/\/www.taterboy.com\/blog\/author\/guestcontribution\/#author"},"image":{"@type":"ImageObject","url":"https:\/\/i0.wp.com\/www.taterboy.com\/blog\/wp-content\/uploads\/2019\/05\/logo-red-17.png?fit=60%2C80&ssl=1","@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#mainImage","width":60,"height":80},"primaryImageOfPage":{"@id":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/#mainImage"},"datePublished":"2019-05-24T04:21:10-07:00","dateModified":"2019-05-24T04:21:10-07:00"},{"@type":"WebSite","@id":"https:\/\/www.taterboy.com\/blog\/#website","url":"https:\/\/www.taterboy.com\/blog\/","name":"Design for Immersive Technologies","description":"User Experience for Games, Virtual Reality (VR) and Augmented\/Mixed Reality (AR\/MR)","inLanguage":"en-US","publisher":{"@id":"https:\/\/www.taterboy.com\/blog\/#organization"}}]},"og:locale":"en_US","og:site_name":"Design for Immersive Technologies | User Experience for Games, Virtual Reality (VR) and Augmented\/Mixed Reality (AR\/MR)","og:type":"article","og:title":"Creating Your Own React Validation Library: The Features (Part 2) | Design for Immersive Technologies","og:description":"Creating Your Own React Validation Library: The Features (Part 2)Creating Your Own React Validation Library: The Features (Part 2) Kristofer Selbekk 2019-05-23T13:00:16+02:002019-05-24T11:09:32+00:00Implementing a validation library isn\u2019t all that hard. Neither is adding all of those extra features that make your validation library much better than the rest. This article will continue implementing the validation library","og:url":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/","article:published_time":"2019-05-24T11:21:10+00:00","article:modified_time":"2019-05-24T11:21:10+00:00","twitter:card":"summary","twitter:title":"Creating Your Own React Validation Library: The Features (Part 2) | Design for Immersive Technologies","twitter:description":"Creating Your Own React Validation Library: The Features (Part 2)Creating Your Own React Validation Library: The Features (Part 2) Kristofer Selbekk 2019-05-23T13:00:16+02:002019-05-24T11:09:32+00:00Implementing a validation library isn\u2019t all that hard. Neither is adding all of those extra features that make your validation library much better than the rest. This article will continue implementing the validation library"},"aioseo_meta_data":{"post_id":"65879","title":null,"description":null,"keywords":null,"keyphrases":null,"canonical_url":null,"og_title":null,"og_description":null,"og_object_type":"default","og_image_type":"default","og_image_custom_url":null,"og_image_custom_fields":null,"og_custom_image_width":null,"og_custom_image_height":null,"og_video":null,"og_custom_url":null,"og_article_section":null,"og_article_tags":null,"twitter_use_og":false,"twitter_card":"default","twitter_image_type":"default","twitter_image_custom_url":null,"twitter_image_custom_fields":null,"twitter_title":null,"twitter_description":null,"schema_type":null,"schema_type_options":null,"pillar_content":false,"robots_default":true,"robots_noindex":false,"robots_noarchive":false,"robots_nosnippet":false,"robots_nofollow":false,"robots_noimageindex":false,"robots_noodp":false,"robots_notranslate":false,"robots_max_snippet":null,"robots_max_videopreview":null,"robots_max_imagepreview":"large","priority":null,"frequency":null,"location":null,"local_seo":null,"created":"2021-02-07 19:51:40","updated":"2026-09-01 11:10:31","focus_keyword":null,"additional_keywords":null,"truseo_locale":null,"primary_term":null,"og_image_url":null,"og_image_width":null,"og_image_height":null,"twitter_image_url":null,"schema":{"blockGraphs":[],"customGraphs":[],"default":{"data":{"Article":[],"Course":[],"Dataset":[],"FAQPage":[],"Movie":[],"Person":[],"Product":[],"ProductReview":[],"Car":[],"Recipe":[],"Service":[],"SoftwareApplication":[],"WebPage":[]},"graphName":"Article","isEnabled":true},"graphs":[]},"limit_modified_date":false,"ai":null,"breadcrumb_settings":null,"seo_analyzer_scan_date":null},"aioseo_breadcrumb":"<div class=\"aioseo-breadcrumbs\"><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.taterboy.com\/blog\" title=\"Home\">Home<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\t<a href=\"https:\/\/www.taterboy.com\/blog\/category\/user-experience\/\" title=\"User Experience\">User Experience<\/a>\n\t\t<\/span><span class=\"aioseo-breadcrumb-separator\">&raquo;<\/span><span class=\"aioseo-breadcrumb\">\n\t\t\tCreating Your Own React Validation Library: The Features (Part 2)\n\t\t<\/span><\/div>","aioseo_breadcrumb_json":[{"label":"Home","link":"https:\/\/www.taterboy.com\/blog"},{"label":"User Experience","link":"https:\/\/www.taterboy.com\/blog\/category\/user-experience\/"},{"label":"Creating Your Own React Validation Library: The Features (Part 2)","link":"https:\/\/www.taterboy.com\/blog\/2019\/05\/creating-your-own-react-validation-library-the-features-part-2\/"}],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8wzr5-h8z","jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.taterboy.com\/blog\/wp-content\/uploads\/2019\/05\/logo-red-17.png?fit=60%2C80&ssl=1","_links":{"self":[{"href":"https:\/\/www.taterboy.com\/blog\/wp-json\/wp\/v2\/posts\/65879","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.taterboy.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.taterboy.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.taterboy.com\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.taterboy.com\/blog\/wp-json\/wp\/v2\/comments?post=65879"}],"version-history":[{"count":0,"href":"https:\/\/www.taterboy.com\/blog\/wp-json\/wp\/v2\/posts\/65879\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.taterboy.com\/blog\/wp-json\/wp\/v2\/media\/65880"}],"wp:attachment":[{"href":"https:\/\/www.taterboy.com\/blog\/wp-json\/wp\/v2\/media?parent=65879"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.taterboy.com\/blog\/wp-json\/wp\/v2\/categories?post=65879"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.taterboy.com\/blog\/wp-json\/wp\/v2\/tags?post=65879"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}