LoginSignup
0
0

More than 1 year has passed since last update.

プロトタイプ変数

Posted at

PropTypes

varやletより厳密な変数宣言、プロトタイプ変数が存在します。
数値や文字列しか格納できなくすることで仕様理解や潜在的なエラー発見が可能になります。

宣言方法
数値     PropTypes.number
文字列    PropTypes.string
論理値    PropTypes.bool
配列     PropTypes.array
関数     PropTypes.func
オブジェクト PropTypes.object

使用例

PropTypes
import PropTypes from 'prop-types';

class MyComponent extends React.Component {
  render() {
    // This must be exactly one element or it will warn.
    const i = this.props.number;
    return (
      <div>{i}</div> //数値以外が格納されるとエラー
    );
  }
}

introduction.propTypes = {
  number: PropTypes.number
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0