From d12c18e329ac4f72c775399ca31cf0356e156bc7 Mon Sep 17 00:00:00 2001 From: Kayne Ruse Date: Fri, 14 Dec 2018 04:45:19 +1100 Subject: [PATCH] Minor tweak to markdown behaviour --- src/pages/markdown_page.jsx | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/pages/markdown_page.jsx b/src/pages/markdown_page.jsx index aef6071..e85d31d 100644 --- a/src/pages/markdown_page.jsx +++ b/src/pages/markdown_page.jsx @@ -7,25 +7,21 @@ class MarkdownPage extends React.Component { super(props); this.state = { - source: props.source, - body: "Loading..." + source: props.source || null, + body: props.body }; } componentDidMount() { - fetch(this.state.source) - .then(result => result.text()) - .then((result) => { - this.setState({ - body: result - }); - }, - //handle errors here instead of a catch block because internet said so - (error) => { - this.setState({ - body: error - }); - }); + //if the source is set, grab it from the server and overwrite the body + if (this.state.source) { + fetch(this.state.source) + .then(result => result.text()) + .then( + result => this.setState({ body: result }), + error => this.setState({ body: error }) + ); + } } render() {