elementType 道具类型验证默认值

elementType prop type validation default value

我想知道 elementType 道具验证的默认道具类型值是什么。如果没有传递任何组件,我只想渲染任何内容。

PrivateRoute.defaultProps = {
  component: ???,
};

PrivateRoute.propTypes = {
  component: elementType,
};

您可以简单地输入 null,因为 React 会忽略它。

PrivateRoute.defaultProps = {
  component: null
};

PrivateRoute.propTypes = {
  component: elementType
};

这样您就不会收到任何警告或错误。