import 'whatwg-fetch'; import React from 'react'; import * as qs from 'query-string'; import Message from './Message'; import Spinner from './Spinner'; export default class Thread extends React.Component { constructor(props) { super(props); this.state = { replies: [] }; } componentDidMount() { this.loadReplies(); } loadReplies() { this.setState({ replies: []}) const { mid } = this.props.match.params; let params = { mid: mid } if (this.props.visitor && this.props.visitor.hash) { params.hash = this.props.visitor.hash }; const url = `https://api.juick.com/thread?${qs.stringify(params)}`; 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 ? ( ) : ( ); } }