Skip to content
This repository has been archived by the owner on Nov 25, 2019. It is now read-only.

Commit

Permalink
add mounted check before setState
Browse files Browse the repository at this point in the history
  • Loading branch information
RafalFilipek committed Apr 9, 2017
1 parent 426c446 commit f5ea929
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type Props = {
mapElements?: { [key: string]: any },
mapInline?: string | Function,
mapBlock?: string | Function,
children?: Function | null
children?: Function | null,
};

class JsxHtml extends PureComponent {
Expand All @@ -22,20 +22,23 @@ class JsxHtml extends PureComponent {
mapElements: PropTypes.object,
mapInline: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
mapBlock: PropTypes.oneOfType([PropTypes.string, PropTypes.func]),
children: PropTypes.func
children: PropTypes.func,
};

static defaultProps: Props = {
html: '',
mapElements: {},
mapInline: '',
mapBlock: '',
children: null
children: null,
};

state = {};

mounted = false;

componentDidMount() {
this.mounted = true;
this.setContent();
}

Expand All @@ -45,14 +48,20 @@ class JsxHtml extends PureComponent {
}
}

componentWillUnmount() {
this.mounted = false;
}

setContent() {
convert(
this.props.html,
this.props.mapElements,
this.props.mapInline,
this.props.mapBlock
).then(content => {
this.setState({ content });
if (this.mounted) {
this.setState({ content });
}
});
}

Expand Down

0 comments on commit f5ea929

Please sign in to comment.