Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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);
Expand Down