import React from 'react'; import { Link } from 'react-router-dom'; import { Helmet } from 'react-helmet'; import { sourceLink, infoLine } from './utils.js'; class Results extends React.Component { constructor(props) { super(props); this.state = { stories: false, error: false, }; } performSearch = () => { const search = this.props.location.search; fetch('/api/search' + search) .then(res => res.json()) .then( (result) => { this.setState({ stories: result.results }); }, (error) => { this.setState({ error: true }); } ); } componentDidMount() { this.performSearch(); } componentDidUpdate(prevProps) { if (this.props.location.search !== prevProps.location.search) { this.performSearch(); } } render() { const stories = this.state.stories; const error = this.state.error; return (
Feed - QotNews {error &&

Connection error?

} {stories ?
{stories.length ? stories.map((x, i) =>
{i+1}.
source logo {x.title} ​({sourceLink(x)})
{infoLine(x)}
) :

no results

}
:

loading...

}
); } } export default Results;