Skip to content

xieyou0608/react-coding-challenges-dark-mode

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

154 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Dark Mode Coding Challenge

This repository is forked from react-coding-challege (only dark-mode part remained)

 

Get started

  • Please check demo website directly.
  • Or run yarn and then run yarn start to start app locally.

Environment

node.js v16.16.0

 

Solution

Approach

題目要求主要於 [feat] Add dark mode 這個 commit 完成,並且只有更動 App.js 檔案。做法為維護一個 boolean state (isDarkMode),按下按鈕後依據當下狀態切換 light/dark 模式, isDarkMode 更新完成後會觸發 side effect(在 html DOM element 增加或刪除 "dark-mode" 這個 class),而按鈕本身的 icon 圖示及顏色也依據 isDarkMode 進行改變(JSX部分)。 Check solution.jpg

Other potential

如果專案發展的較大,在大量頁面或元件都需要依賴 isDarkMode 做改變的情況下,使用 useState Hook 加上 props 傳遞會相當難以開發,可以改成使用 Context API 或 Redux 來維護 isDarkMode,並且由用到 isDarkMode 的元件訂閱 store 即可。

 

Ref

 

Contact

Feel free to contact me! :email: xyc.hsieh@gmail.com

About

A series of ReactJS coding challenges with a variety of difficulties.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • JavaScript 46.7%
  • SCSS 28.5%
  • HTML 24.8%