Skip to content

ania221B/github-user-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Frontend Mentor - GitHub user search app solution

This is a solution to the GitHub user search app 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 app depending on their device's screen size
  • See hover states for all interactive elements on the page
  • Search for GitHub users by their username
  • See relevant user information based on their search
  • Switch between light and dark themes
  • Bonus: Have the correct color scheme chosen for them based on their computer preferences. Hint: Research prefers-color-scheme in CSS.

Screenshot

Mobile view Tablet view Desktop view

Links

My process

Built with

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

What I learned

There are many ways of adding classes in React conditionally. A great resource detailing them is provided in Useful resources section. One of the said methods is using an array and join() method:

function myComponent() {
  const classes = []
  if (isError) {
    classes.push('error')
  } else if (isWarining) {
    classes.push('warning')
  } else if (isInfo) {
    classes.push('info')
  } else {
    const indexOfError = searchBarClasses.indexOf('error')
    const indexOfWarning = searchBarClasses.indexOf('warning')
    const indexOfInfo = searchBarClasses.indexOf('info')
    searchBarClasses.splice(indexOfError - 1, 1)
    searchBarClasses.splice(indexOfWarning - 1, 1)
    searchBarClasses.splice(indexOfInfo - 1, 1)
  }

  return (
    <article className={`base-style` + ' ' + classes.join(' ')}>
      <h2>This is my component</h2>
      <p>
        Here is some info aobut it. This component was created using React. The
        classes it uses are added conditionally with an array and join() method
      </p>
    </article>
  )
}

I decided to use an empty array and have some classes for my component by default. This is because the ones I was using were for basic styling, so whole thing looked really ugly for a split second while loading when the said classes were missing. Yet you can have some items in the array if appropriate. While the article I've learnt this from doesn't really show that, you also need to make sure to remove the classes, when they're no longer needed.

Continued development

  • React
  • Intersection Observer
  • Sass

Useful resources

Author

Releases

No releases published

Packages

No packages published