Skip to content
  • Unlock Pro
  • Log in with GitHub
Solution
Submitted almost 2 years ago

Github User Search App w/React

accessibility, bem, react, fetch
P
Mina Makhlouf•1,150
@Minamakhlouf
A solution to the GitHub user search app challenge
View live sitePreview (opens in new tab)View codeCode (opens in new tab)

Solution retrospective


Problem #1: Getting the users preferred color scheme to work in all browsers

I was able to get the users preferred color scheme with the userMediaQuery hook const prefersDarkMode = useMediaQuery('(prefers-color-scheme: dark)')

However, I found that this would not work on all browsers. It worked on Firefox but was inconsistent on Chrome. I learned that sometimes outside forces can effect this like Operating System Dark Mode, Web Page issues, Browser compatibility or Operating system compatibility.

If someone had better success than me with this issue using React, I would appreciate the advice.

Problem #2: The GitHub API does not reject a fetch request even if there is an error. It will respond to it and in the response body it will say "response.ok = false".

I had a difficult time understanding this and resolving this but what I ended up doing is checking if (!response.ok) { throw new Error(`HTTP Error! status ${response.status}) }

It looks like this: if (!response.ok) { throw new Error(HTTP Error! status ${response.status}); }

What this taught me is that you have to read the API documentation because not all APIs respond to Promises like you expect them to.

Aside from that, if there is any other feedback or help, it would be greatly appreciated.

Code
Loading...

Please log in to post a comment

Log in with GitHub

Community feedback

No feedback yet. Be the first to give feedback on Mina Makhlouf's solution.

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord

Stay up to datewith new challenges, featured solutions, selected articles, and our latest news

Frontend Mentor

  • Unlock Pro
  • Contact us
  • FAQs
  • Become a partner
  • Use cases

Explore

  • Learning paths
  • Challenges
  • Solutions
  • Articles

Community

  • Discord
  • Guidelines

For companies

  • Hire developers
  • Train developers
© Frontend Mentor 2019 - 2025
  • Terms
  • Cookie Policy
  • Privacy Policy
  • License