import "whatwg-fetch" import React from "react" import PropTypes from "prop-types" import Message from "./Message" export default class Discover extends React.Component { constructor(props) { super(props) this.state = { msgs: [], loading: false } this.loadMessages = this.loadMessages.bind(this); } componentDidMount() { this.loadMessages(); } componentWillReceiveProps(props) { if (props.params != this.props.params) { this.loadMessages(); } } loadMessages() { const search = new URLSearchParams(this.props.params); const url = "https://api.juick.com/messages"; fetch(url) .then(response => { return response.json() }) .then(data => this.setState({ msgs: data }) ).catch(ex => { console.log(ex) }); } render() { var nodes = this.state.msgs.map(msg => { return () }); return (
{nodes}
) } }; Discover.propTypes = { msgs: PropTypes.array }