O'Reilly logo

React and React Native - Second Edition by Adam Boduch

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Basic type validation

Let's take a look at validators that handle the most primitive types of JavaScript values. You will use these validators frequently, as you'll want to know that a property is a string or that it's a function, for example. This example will also introduce you to the mechanisms involved with setting up validation on a component. Here's the component; it just renders some properties using basic markup:

import React from 'react';import PropTypes from 'prop-types';const MyComponent = ({  myString,  myNumber,  myBool,  myFunc,  myArray,  myObject}) => (  <section>    {/* Strings and numbers can be rendered         just about anywhere. */}    <p>{myString}</p>    <p>{myNumber}</p>    {/* Booleans are typically used as property values. */}    <p> <input ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required