import React, { useState, useEffect } from 'react'; import { Link, useLocation } from 'react-router-dom'; import { Helmet } from 'react-helmet'; import { sourceLink, infoLine, logos } from './utils.js'; import AbortController from 'abort-controller'; function Results() { const [stories, setStories] = useState(false); const [error, setError] = useState(false); const location = useLocation(); useEffect(() => { const controller = new AbortController(); const signal = controller.signal; const search = location.search; fetch('/api/search' + search, { method: 'get', signal: signal }) .then(res => res.json()) .then( (result) => { setStories(result.hits); }, (error) => { if (error.message !== 'The operation was aborted. ') { setError(true); } } ); return () => { controller.abort(); }; }, [location.search]); return (
Search Results | QotNews {error &&

Connection error?

} {stories ? <>

Search results:

{stories.length ? stories.map(x =>
source logo {x.title} ({sourceLink(x)})
{infoLine(x)}
) :

none

}
:

loading...

}
); } export default Results;