import 'whatwg-fetch'; import React from 'react'; import Message from './Message'; import Spinner from './Spinner'; export default class Thread extends React.Component { constructor(props) { super(props); this.state = { replies: [], loading: false }; } componentDidMount() { this.loadReplies(); } loadReplies() { this.setState({ replies: []}) const { mid } = this.props.match.params; const url = `https://api.juick.com/thread?mid=${mid}`; fetch(url) .then(response => { return response.json() }) .then(data => this.setState({ replies: data }) ).catch(ex => { console.log(ex); }); } render() { return this.state.replies && this.state.replies.length > 0 ? ( ) : ( ); } }