Skip to content

lexzee/product-preview-comp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frontend Mentor - Product preview card component solution

This is a solution to the Product preview card component challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Note: Delete this note and update the table of contents based on what sections you keep.

Overview

The challenge

Users should be able to:

  • View the optimal layout depending on their device's screen size
  • See hover and focus states for interactive elements

Screenshot

Design preview for the Product preview card component coding challenge

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox
  • CSS Grid
  • Mobile-first workflow
  • React - JS library

What I learned

I learnt how to use conditional rendering that depends on window width.

See code snippet, see below:

function App = () => {
  const [isMobile, setIsMobile] = useState(false);

    useEffect(() => {
      const handleView = () => {
        setIsMobile(window.innerWidth < 780);
      };
      handleView();
      window.addEventListener('resize', handleView);

      return () => {
        window.removeEventListener('resize', handleView);
      }
    }, [])

  return (
    <div className="App">
      {isMobile ? <Mobile /> : <Desktop />}
    </div>
  );
}

Author

Releases

No releases published

Packages

No packages published