mariechanaron.github.io/playing-hooky
This project is implementing a light/dark theme feature in a Todo list React application using a custom hook. The custom hook has two features:
- it toggles the theme (on clicking on the button on the top right),
- it returns the current theme (to change the button text).
We are using the 'data-theme' custom data attribute to save our theme state in the DOM when the page loads. In index.css we are using the data-theme attribute to change the styling of our page when the value is set to 'dark'. The data-theme attribute is set in the effect callback of the useTheme custom hook, with the following code: document.documentElement.setAttribute('data-theme', theme);
React Version 18.2.0