From a2ffaac9031da98cd01277bb2f6532faa9363a80 Mon Sep 17 00:00:00 2001 From: Ross Solomon Date: Tue, 11 Apr 2017 16:36:30 -0700 Subject: [PATCH 1/2] Use prop-types; don't use React.createClass --- index.js | 16 ++++++++++------ package.json | 2 ++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 857a506..382f9cd 100644 --- a/index.js +++ b/index.js @@ -1,6 +1,7 @@ 'use strict'; var React = require('react'), + PropTypes = require('prop-types'), withSideEffect = require('react-side-effect'); function reducePropsToState(propsList) { @@ -17,13 +18,12 @@ function handleStateChangeOnClient(title) { } } -var DocumentTitle = React.createClass({ - displayName: 'DocumentTitle', - - propTypes: { - title: React.PropTypes.string.isRequired - }, +function DocumentTitle() { + React.Component.call(this); +} +DocumentTitle.prototype = Object.assign(Object.create(React.Component.prototype), { + constructor: DocumentTitle, render: function render() { if (this.props.children) { return React.Children.only(this.props.children); @@ -33,6 +33,10 @@ var DocumentTitle = React.createClass({ } }); +DocumentTitle.propTypes = { + title: PropTypes.string.isRequired +}; + module.exports = withSideEffect( reducePropsToState, handleStateChangeOnClient diff --git a/package.json b/package.json index 7926dac..dc44bb1 100644 --- a/package.json +++ b/package.json @@ -34,6 +34,8 @@ "react": "^0.13.0" }, "dependencies": { + "prop-types": "^15.5.0", + "react": "^15.5.0", "react-side-effect": "^1.0.2" } } From 8d78a48dae64e5e6f0467a250f541f7278aedded Mon Sep 17 00:00:00 2001 From: Ross Solomon Date: Tue, 11 Apr 2017 16:44:14 -0700 Subject: [PATCH 2/2] Add back displayName --- index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/index.js b/index.js index 382f9cd..cbfd670 100644 --- a/index.js +++ b/index.js @@ -20,6 +20,7 @@ function handleStateChangeOnClient(title) { function DocumentTitle() { React.Component.call(this); + this.displayName = 'DocumentTitle'; } DocumentTitle.prototype = Object.assign(Object.create(React.Component.prototype), {