Skip to content

This is a solution to the Job listings with filtering challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building real projects.

Notifications You must be signed in to change notification settings

SyedZawwarAhmed/static-job-listings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frontend Mentor - Job listings with filtering solution

This is a solution to the Job listings with filtering challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.

Table of contents

Overview

The challenge

Users should be able to:

  • View the optimal layout for the site depending on their device's screen size
  • See hover states for all interactive elements on the page
  • Filter job listings based on the categories

Here is what it looks like

Desktop preview

Links

My process

Built with

  • React - JS library
  • CSS custom properties
  • Flexbox
  • CSS Grid

What I learned

The most important thing I learned while making this that when the state of a functional component is changed, its value can't be immediately accessed on the same render. You have to call the setState function which the useState hook returns to access the recently updated state.

Here is the code snippet of what I am talking about:

const applyFilter = (newFilter) => {
  setIsFilterApplied(true);
  if (!filter.map((item) => item[1]).includes(newFilter[1])) {
    setFilter((filter) => [...filter, newFilter]);
  }
  setFilter((filter) => {
    for (let i = 0; i < data.length; i++) {
      const item = data[i];
      let filterPassed = true;

      for (let j = 0; j < filter.length; j++) {
        const filterItem = filter[j];
        if (filterItem[0] === "languages") {
          filterPassed = item[filterItem[0]].includes(filterItem[1]);
        } else {
          filterPassed = filterItem[1] === item[filterItem[0]];
        }

        if (!filterPassed) break;
      }
      item.filterApplied = filterPassed;
    }
    return filter;
  });
};

Continued development

The most important thing I want to focus on in the future is the useEffect hook. I know when it's used but the how part is to be worked on.

Useful resources

  • stackoverflow - As always, when I got stuck, stackoverflow helped me get through.
  • React - This is an amazing article which helped me get a know how of the useEffect Hook. I'd recommend it to anyone still learning this concept.

Author

About

This is a solution to the Job listings with filtering challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building real projects.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published