Last active
January 2, 2020 17:21
-
-
Save debonx/da429d37bf875cb6ab8b902b44c9d571 to your computer and use it in GitHub Desktop.
React: How to set propTypes stateless component.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
export class BestSeller extends React.Component { | |
render() { | |
return ( | |
<li> | |
Title: <span> | |
{this.props.title} | |
</span><br /> | |
Author: <span> | |
{this.props.author} | |
</span><br /> | |
Weeks: <span> | |
{this.props.weeksOnList} | |
</span> | |
</li> | |
); | |
} | |
} | |
// 1. Define propTypes as static object literal | |
// 2. The name of each property in propTypes should be the name of an expected prop | |
BestSeller.propTypes = { | |
title: React.PropTypes.string.isRequired, | |
author: React.PropTypes.string.isRequired, | |
weeksOnList: React.PropTypes.number.isRequired | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment