Giter VIP home page Giter VIP logo

hackernews's Introduction

Hacker News App

A simple App that fetches data from the Hacker News Top Stories API and displays a list of the individual stories.

Screen-Shot-2021-10-26-at-13-33-31.png

Approach

The UI is built using React + Typescript and styled using Styled-Components. Framer-Motion is used for UI animations. A SkeltonLoader component is shown while data is being fetched from the API and a useInfiniteScroll custom hook is used to render more data as the user reaches near the bottom of the page. The fetchStories async function handles the API calls and toggles the isFetching state. The storyIds from the first API call are sliced and mapped accordingly with the count from the useInfiniteScroll hook to return data for each story. When the use clicks on the title of the individual story, they are navigated to the actual page on a new tab.

Optimizations

The ListItems component is wrapped in the React.memo higher order component to stop unnecessary rendering of the component unless the props have changed in value. The serviceWorker.ts file registers a service-worker to cache the page results to speed up subsequent loads of the page.

Tests

React-testing-library is used along with MSW to make sure the UI is rendered correctly and by mocking the API calls. By using MSW, we can avoid directly mocking the Fetch API and still have confidence that the fetch function is being called correctly.

hackernews's People

Contributors

yutaasato avatar

Stargazers

Roman avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.