Coder Social home page Coder Social logo

shopping-cart's Introduction

shopping-cart

This is a SPA for a mock shop built with React. The main goals of this project were to try simple unit testing in a React environment, fetching data and error-handling requests, and practicing routing with React Router.

Live version of this project can be found here: https://ken-ux.github.io/shopping-cart/

Lessons Learned

  • Scoping styles to components with CSS modules. This helped eliminate pollution of the global namespace when writing identical class names across components.
  • Implementing nested routes and dynamic segments using React Router.
  • Improving user experience by setting a "load" message while data is being fetched.
  • Writing tests with React Testing Library.
  • An early issue I ran into was running tests on components that contained React Router's Link component.
    • When ran on components in isolation, an error would occur. Link always has to be used inside of a router, so testing a component containing Link without wrapping the component in one would always throw an error. Therefore, mocking a router by wrapping the component in React Router's lightweight MemoryRouter component in a test was a simple fix.
  • Avoiding "requests waterfalls" by resolving promises in the topmost components.
    • For example, rendering my ShopItem component would involve fetching the data for each item and displaying a loading message before they're rendered. A page of six ShopItem components would therefore show six individual loading messages. After refactoring, the data was instead fetched all at once in its parent component, Shop, then distributed to its child components. This ensured only one loading message needed to be shown when Shop was fetching data.

Credits

shopping-cart's People

Contributors

ken-ux 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.