ReactJS Foundations

Listing 6-3: Validating That a Prop is a String

Previous Listing | Next Listing

Welcome back, Test!

import PropTypes from 'prop-types';

function WelcomeMessage(props){
  return (<p>Welcome back, {props.firstName}!</p>);
}
  
WelcomeMessage.propTypes = {
  firstName:PropTypes.string
}

export default WelcomeMessage;

Download the examples, report issues, and ask/answer questions in the discussion area by visiting the book's github page. All of the code for the book is also available on codesandbox.io for you to play around with.

ReactJS Foundations is published by John Wiley and Sons, Inc and is available in paperback and eBook.

React JS Foundations

Loading...