Minor tweak to markdown behaviour

This commit is contained in:
2018-12-14 04:45:19 +11:00
parent 3fe8ccddef
commit d12c18e329
+9 -13
View File
@@ -7,25 +7,21 @@ class MarkdownPage extends React.Component {
super(props); super(props);
this.state = { this.state = {
source: props.source, source: props.source || null,
body: "Loading..." body: props.body
}; };
} }
componentDidMount() { componentDidMount() {
//if the source is set, grab it from the server and overwrite the body
if (this.state.source) {
fetch(this.state.source) fetch(this.state.source)
.then(result => result.text()) .then(result => result.text())
.then((result) => { .then(
this.setState({ result => this.setState({ body: result }),
body: result error => this.setState({ body: error })
}); );
}, }
//handle errors here instead of a catch block because internet said so
(error) => {
this.setState({
body: error
});
});
} }
render() { render() {