diff --git a/src/App.js b/src/App.js index 8e8b394e9..78b9cdc27 100644 --- a/src/App.js +++ b/src/App.js @@ -1,31 +1,6 @@ import React from 'react'; -const initialStories = [ - { - title: 'React', - url: 'https://reactjs.org/', - author: 'Jordan Walke', - num_comments: 3, - points: 4, - objectID: 0, - }, - { - title: 'Redux', - url: 'https://redux.js.org/', - author: 'Dan Abramov, Andrew Clark', - num_comments: 2, - points: 5, - objectID: 1, - }, -]; - -const getAsyncStories = () => - new Promise(resolve => - setTimeout( - () => resolve({ data: { stories: initialStories } }), - 2000 - ) - ); +const API_ENDPOINT = 'https://hn.algolia.com/api/v1/search?query='; const useSemiPersistentState = (key, initialState) => { const [value, setValue] = React.useState( @@ -86,11 +61,12 @@ const App = () => { React.useEffect(() => { dispatchStories({ type: 'STORIES_FETCH_INIT' }); - getAsyncStories() + fetch(`${API_ENDPOINT}react`) + .then(response => response.json()) .then(result => { dispatchStories({ type: 'STORIES_FETCH_SUCCESS', - payload: result.data.stories, + payload: result.hits, }); }) .catch(() =>