如何在使用react-transition-group时修复React 15.5.3 PropTypes不推荐使用的警告

问题描述 投票:5回答:2

伙计们! 有没有人得到"Warning: Accessing PropTypes via the main React package is deprecated. Use the prop-types package from npm instead." 使用React 15.5.3 "react-transition-group/CSSTransitionGroup"附加组件。

看起来这个插件使用旧的PropTypes。 有人知道如何避免这个加载项的警告吗?

reactjs react-proptypes
2个回答
1
投票

它在React版本15.5之后已被弃用。 因此,您需要单独安装它。
安装:npm install prop-types

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

class Component extends React.Component {
  render() {
    return <div>{this.props.text}</div>;
  }
}

Component.propTypes = {
  text: PropTypes.string.isRequired,
};

编辑 :您需要获得与更新兼容的更新包以及最新更新。 包装尚未更新,您可以自行更改它们。


1
投票

当我将“react-transition-group”更新为最新版本时,此错误会自动修复。 看起来npm包现在适用于'prop-types'的PropTypes。

© www.soinside.com 2019 - 2024. All rights reserved.