Advertisement
LTroya

PropTypes validations

Nov 11th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, {Component} from 'react';
  2.  
  3. export class Profile extends Component {
  4.   render() {
  5.     const hobbies = this.props.hobbies.map(hobby => {
  6.       return <li key={hobby}>{hobby}</li>;
  7.     });
  8.     return (
  9.       <div>
  10.         <h3>{this.props.name}</h3>
  11.         <p>{this.props.name} {this.props.bio}</p>
  12.         <h3>Hobbies</h3>
  13.         <ul>{hobbies}</ul>
  14.       </div>
  15.     );
  16.   }
  17. }
  18.  
  19. Profile.propTypes = {
  20.   name: React.PropTypes.string.isRequired,
  21.   bio: React.PropTypes.string.isRequired,
  22.   hobbies: React.PropTypes.array.isRequired
  23. };
  24.  
  25. export class Hello extends Component {
  26.   constructor(pros) {
  27.     super(pros);
  28.     this.state = {
  29.       profiles: [
  30.         {name: 'Sue', age: 30, bio: 'enjoys swimming and biking', hobbies: ['swimming', 'biking']},
  31.         {name: 'Bill', age: 40, bio: 'enjoys long walks on the beach', hobbies: ['gardening', 'games']}
  32.       ]
  33.     };
  34.   }
  35.  
  36.   render() {
  37.     return (
  38.       <div>
  39.         <Profile data={this.state.profiles[0]}/>
  40.       </div>
  41.     );
  42.   }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement