diff --git a/src/App.js b/src/App.js index 78b9cdc27..474c5806b 100644 --- a/src/App.js +++ b/src/App.js @@ -59,9 +59,11 @@ const App = () => { ); React.useEffect(() => { + if (!searchTerm) return; + dispatchStories({ type: 'STORIES_FETCH_INIT' }); - fetch(`${API_ENDPOINT}react`) + fetch(`${API_ENDPOINT}${searchTerm}`) .then(response => response.json()) .then(result => { dispatchStories({ @@ -72,7 +74,7 @@ const App = () => { .catch(() => dispatchStories({ type: 'STORIES_FETCH_FAILURE' }) ); - }, []); + }, [searchTerm]); const handleRemoveStory = item => { dispatchStories({ @@ -85,10 +87,6 @@ const App = () => { setSearchTerm(event.target.value); }; - const searchedStories = stories.data.filter(story => - story.title.toLowerCase().includes(searchTerm.toLowerCase()) - ); - return (

My Hacker Stories

@@ -109,10 +107,7 @@ const App = () => { {stories.isLoading ? (

Loading ...

) : ( - + )}
);