by Pawan Kumar @jsartisan
Implement a React component that fetches and displays stories from the Hacker News API.
-
Use the endpoint:
https://hacker-news.firebaseio.com/v0/topstories.jsonto get a list of top story IDs.
-
For each story ID, fetch the story details from:
https://hacker-news.firebaseio.com/v0/item/{id}.json
Requirements:
- Fetch the list of top story IDs.
- Display the stories 5 at a time.
- Include a “Load More” button to fetch the next 5 stories.
- Show a loading state while fetching.
- Show an error state if the API request fails.
- On success, display each story’s title as a clickable link to its URL.
- Use React hooks (
useState,useEffect) to manage state.
Bonus:
- Disable the “Load More” button when no more stories are left.
- Handle retries if a fetch request fails.