diff --git a/src/App.js b/src/App.js index 678b5141a..eb454f20d 100644 --- a/src/App.js +++ b/src/App.js @@ -63,20 +63,19 @@ const App = () => { { data: [], isLoading: false, isError: false } ); - const handleFetchStories = React.useCallback(() => { + const handleFetchStories = React.useCallback(async () => { dispatchStories({ type: 'STORIES_FETCH_INIT' }); - axios - .get(url) - .then(result => { - dispatchStories({ - type: 'STORIES_FETCH_SUCCESS', - payload: result.data.hits, - }); - }) - .catch(() => - dispatchStories({ type: 'STORIES_FETCH_FAILURE' }) - ); + try { + const result = await axios.get(url); + + dispatchStories({ + type: 'STORIES_FETCH_SUCCESS', + payload: result.data.hits, + }); + } catch { + dispatchStories({ type: 'STORIES_FETCH_FAILURE' }); + } }, [url]); React.useEffect(() => {