LoginSignup
1

More than 3 years have passed since last update.

[メモ] React.FC の PropTypes 指定

Posted at

[メモ] React.FC の PropTypes 指定

React.FC で PropTypes を使用する場合に以下の記述にする

react-prop-types
import PropTypes from 'prop-types';
import React from 'react';

/** Props の型を定義 */
type Props = {
  /** こども */
  children?: React.ReactNode;
};

/**
 * Component.propTypes に指定する変数
 * - 上記の Props を `React.WeakValidationMap` に渡す
 */
const propTypes: React.WeakValidationMap<Props> = {
  children: PropTypes.node,
};

const Component: React.FC<Props> = (props) => <div>{props.children}</div>;

Component.propTypes = propTypes;
export default Component;

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
1