Skip to content

Latest commit

 

History

History
35 lines (26 loc) · 615 Bytes

prop-types-default-props.md

File metadata and controls

35 lines (26 loc) · 615 Bytes


propTypes & defaultProps

  • How to define propTypes, defaultProps, contextTypes, etc...
import React, { Component, PropTypes } from 'react';

const propTypes = {
  id: PropTypes.number.isRequired,
  url: PropTypes.string.isRequired,
  text: PropTypes.string,
};

const defaultProps = {
  text: 'Hello World',
};

class Link extends Component {
  static methodsAreOk() {
    return true;
  };

  render() {
    return <a href={this.props.url} data-id={this.props.id}>{this.props.text}</a>
  }
}

Link.propTypes = propTypes;
Link.defaultProps = defaultProps;

export default Link;