diff --git a/src/index.js b/src/index.js index 46c7336..3e4bca9 100644 --- a/src/index.js +++ b/src/index.js @@ -1,9 +1,24 @@ 'use strict'; import React from 'react'; +import PropTypes from 'prop-types'; import Markdown from 'remarkable'; class Remarkable extends React.Component { + static propTypes = { + container: PropTypes.string, + options: PropTypes.object, + source: PropTypes.string, + children: PropTypes.oneOfType([ + PropTypes.arrayOf(PropTypes.node), + PropTypes.node + ]) + } + + static defaultProps = { + container: 'div', + options: {} + } render() { var Container = this.props.container; @@ -15,6 +30,21 @@ class Remarkable extends React.Component { ); } + shouldComponentUpdate(nextProps, nextState) { + if (nextProps.options !== this.props.options) { + return true; + } + else if (this.props.source) { + return this.props.source !== nextProps.source; + } + else if (React.Children.count(this.props.children) === 1 && React.Children.count(nextProps.children) === 1) { + return (typeof this.props.children === 'string') && this.props.children !== nextProps.children; + } + else { + return true; + } + } + componentWillUpdate(nextProps, nextState) { if (nextProps.options !== this.props.options) { this.md = new Markdown(nextProps.options);