From 04c9780ee10a6f27778586a3ae0eeb98e3210af2 Mon Sep 17 00:00:00 2001 From: Andrey Okonetchnikov Date: Thu, 22 Sep 2016 21:53:11 +0200 Subject: [PATCH] Better implementation --- src/components/Widgets/MarkitupReactRenderer.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/components/Widgets/MarkitupReactRenderer.js b/src/components/Widgets/MarkitupReactRenderer.js index d8f226a7..40459162 100644 --- a/src/components/Widgets/MarkitupReactRenderer.js +++ b/src/components/Widgets/MarkitupReactRenderer.js @@ -51,13 +51,20 @@ function renderToken(token, index = 0, key = '0') { export default class MarkitupReactRenderer extends React.Component { - render() { - const { value, syntax } = this.props; + constructor(props) { + super(props); + const { syntax } = props; + this.parser = new MarkupIt(syntax); + } - if (typeof this.parser === 'undefined') { - this.parser = new MarkupIt(syntax); + componentWillReceiveProps(nextProps) { + if (nextProps.syntax != this.props.syntax) { + this.parser = new MarkupIt(nextProps.syntax); } + } + render() { + const { value } = this.props; const content = this.parser.toContent(value); const json = JSONUtils.encode(content); // console.log(JSON.stringify(json, null, 2));