使用 react-transition-group 时如何修复 React 15.5.3 PropTypes 弃用警告
How to fix React 15.5.3 PropTypes deprecated warning while using react-transition-group
伙计们!
有没有人得到
"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。
有人知道如何避免此附加组件的警告吗?
在 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,
};
编辑:您需要获取与 React 最新更新兼容的附加组件的更新包。如果包还没有更新,你可以自己修改。
当我将 "react-transition-group" 更新到最新版本时,此错误会自动修复。看起来 npm 包现在适用于 'prop-types' 的 PropTypes。
伙计们!
有没有人得到
"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。 有人知道如何避免此附加组件的警告吗?
在 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,
};
编辑:您需要获取与 React 最新更新兼容的附加组件的更新包。如果包还没有更新,你可以自己修改。
当我将 "react-transition-group" 更新到最新版本时,此错误会自动修复。看起来 npm 包现在适用于 'prop-types' 的 PropTypes。