There are lots of tutorials that require adding separte
CSS for light and dark theme. However I wanted to leverage a simple
First we need to import necessary files to our html file.
We can use FontAwesome to add
moon icon for light mode and
sun icon for dark mode.
On clicking the button, we need to call the function
localStorage object allows you to save key/value pairs in the browser. This is useful to save the state of your application between page loads.
Lastly we need to call
setFetchMethod to check if the browser is using
darkmode before enabling or disabling it.