Skip to content

About

I'm rebuilding product list challenge to learn React and Tailwind

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Product list - React

Table of contents

Overview

I previously built this challenge with vanilla HTML/CSS/JS, but my JavaScript logic became complex and hard to maintain. I also wanted to separate data and logic from UI code, so I decided to rebuild the project using React. Since I was already familiar with the project, rebuilding it in React helped me practice React concepts. I also experimented with Tailwind CSS — configuring and learning it was a bit confusing at first, but writing styles with Tailwind later became straightforward and enjoyable.

live site URL

Live Site URL

My process

Built with

  • React & Tailwind 😀

What I learned

  • Maps cannot be serialized directly with JSON.stringify. First convert the Map to an array, then stringify the array. To restore it, parse the JSON back to an array and create a Map from that array.
  • The dialog element has default positioning and behavior, so instead of styling the dialog element directly, wrap its contents in a div and style that wrapper.
  • In Tailwind, using constructs like w-[min(100%, 10rem)] requires no spaces inside the brackets. Spaces can prevent Tailwind's parser from recognizing the utility.
  • A helpful pattern when using React + Tailwind: when a component accepts a className prop, the parent-level classes passed down are not automatically merged into the component's inner elements. To allow external layout classes to affect the component, accept a className prop and append it to the component's internal className inside the component.
  • Internal styles vs layout styles in components: internal styles define the component's intrinsic appearance and should live inside the component. Layout styles (for positioning, grid, flex properties used by the parent) should be applied by the parent where the component is used, keeping components reusable.
  • useEffect hook in React: useEffect is appropriate when a component needs to synchronize with an external system (browser API, server, etc.) or perform side effects after render. Recap:
    • Data required for rendering -> use props (pure, static).
    • Data that changes because of user interaction -> use state (dynamic).
    • Actions that should happen as a result of rendering and that interact with external systems -> useEffect (side effects). Subtleties:
    • Dependency array controls when the effect runs again based on changes to dependencies.
    • Returning a cleanup function is for unmounting or when dependencies change; cleanups remove listeners or subscriptions to prevent leaks.

Author

Attribution

About

I'm rebuilding product list challenge to learn React and Tailwind

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages