From 1991a255a10ccc00fc05e7ebe00b5e25b8cba6b3 Mon Sep 17 00:00:00 2001 From: afc163 Date: Thu, 27 Apr 2017 14:53:26 +0800 Subject: [PATCH] fix react createClass and PropTypes warning --- package.json | 4 ++-- src/Notice.jsx | 49 +++++++++++++++++++++----------------------- src/Notification.jsx | 49 +++++++++++++++++++++----------------------- tests/index.js | 2 +- 4 files changed, 49 insertions(+), 55 deletions(-) diff --git a/package.json b/package.json index 946312d..e673ff4 100644 --- a/package.json +++ b/package.json @@ -46,7 +46,6 @@ "pre-commit": "1.x", "rc-tools": "5.x", "react": "15.x", - "react-addons-test-utils": "15.x", "react-dom": "15.x" }, "precommit": [ @@ -54,8 +53,9 @@ ], "dependencies": { "classnames": "2.x", + "prop-types": "^15.5.8", "rc-animate": "2.x", - "rc-util": "4.0.2" + "rc-util": "4.x" }, "pre-commit": [ "lint" diff --git a/src/Notice.jsx b/src/Notice.jsx index 218eac2..64f1809 100644 --- a/src/Notice.jsx +++ b/src/Notice.jsx @@ -1,25 +1,24 @@ -import React, { PropTypes } from 'react'; +import React, { Component } from 'react'; import classNames from 'classnames'; +import PropTypes from 'prop-types'; -const Notice = React.createClass({ - propTypes: { +export default class Notice extends Component { + static propTypes = { duration: PropTypes.number, onClose: PropTypes.func, children: PropTypes.any, - }, + }; - getDefaultProps() { - return { - onEnd() { - }, - onClose() { - }, - duration: 1.5, - style: { - right: '50%', - }, - }; - }, + static defaultProps = { + onEnd() { + }, + onClose() { + }, + duration: 1.5, + style: { + right: '50%', + }, + }; componentDidMount() { if (this.props.duration) { @@ -27,23 +26,23 @@ const Notice = React.createClass({ this.close(); }, this.props.duration * 1000); } - }, + } componentWillUnmount() { this.clearCloseTimer(); - }, + } - clearCloseTimer() { + clearCloseTimer = () => { if (this.closeTimer) { clearTimeout(this.closeTimer); this.closeTimer = null; } - }, + } - close() { + close = () => { this.clearCloseTimer(); this.props.onClose(); - }, + } render() { const props = this.props; @@ -63,7 +62,5 @@ const Notice = React.createClass({ } ); - }, -}); - -export default Notice; + } +} diff --git a/src/Notification.jsx b/src/Notification.jsx index a92a150..a94f5e3 100644 --- a/src/Notification.jsx +++ b/src/Notification.jsx @@ -1,4 +1,5 @@ -import React, { PropTypes } from 'react'; +import React, { Component } from 'react'; +import PropTypes from 'prop-types'; import ReactDOM from 'react-dom'; import Animate from 'rc-animate'; import createChainedFunction from 'rc-util/lib/createChainedFunction'; @@ -12,30 +13,26 @@ function getUuid() { return `rcNotification_${now}_${seed++}`; } -const Notification = React.createClass({ - propTypes: { +class Notification extends Component { + static propTypes = { prefixCls: PropTypes.string, transitionName: PropTypes.string, animation: PropTypes.oneOfType([PropTypes.string, PropTypes.object]), style: PropTypes.object, - }, + }; - getDefaultProps() { - return { - prefixCls: 'rc-notification', - animation: 'fade', - style: { - top: 65, - left: '50%', - }, - }; - }, + static defaultProps = { + prefixCls: 'rc-notification', + animation: 'fade', + style: { + top: 65, + left: '50%', + }, + }; - getInitialState() { - return { - notices: [], - }; - }, + state = { + notices: [], + }; getTransitionName() { const props = this.props; @@ -44,9 +41,9 @@ const Notification = React.createClass({ transitionName = `${props.prefixCls}-${props.animation}`; } return transitionName; - }, + } - add(notice) { + add = (notice) => { const key = notice.key = notice.key || getUuid(); this.setState(previousState => { const notices = previousState.notices; @@ -56,15 +53,15 @@ const Notification = React.createClass({ }; } }); - }, + } - remove(key) { + remove = (key) => { this.setState(previousState => { return { notices: previousState.notices.filter(notice => notice.key !== key), }; }); - }, + } render() { const props = this.props; @@ -87,8 +84,8 @@ const Notification = React.createClass({ {noticeNodes} ); - }, -}); + } +} Notification.newInstance = function newNotificationInstance(properties) { const { getContainer, ...props } = properties || {}; diff --git a/tests/index.js b/tests/index.js index 34f4dee..1dce590 100644 --- a/tests/index.js +++ b/tests/index.js @@ -1,5 +1,5 @@ const React = require('react'); -const TestUtils = require('react-addons-test-utils'); +const TestUtils = require('react-dom/test-utils'); const expect = require('expect.js'); const Notification = require('../');