diff --git a/src/components/ThemeToggle.js b/src/components/ThemeToggle.js new file mode 100644 index 0000000..a3f78f3 --- /dev/null +++ b/src/components/ThemeToggle.js @@ -0,0 +1,24 @@ +import React, { useState, useEffect } from 'react'; + +const ThemeToggle = () => { + const [theme, setTheme] = useState('light'); + + useEffect(() => { + const savedTheme = localStorage.getItem('theme'); + if (savedTheme) { + setTheme(savedTheme); + document.documentElement.setAttribute('data-theme', savedTheme); + } + }, []); + + const toggleTheme = () => { + const newTheme = theme === 'light' ? 'dark' : 'light'; + setTheme(newTheme); + document.documentElement.setAttribute('data-theme', newTheme); + localStorage.setItem('theme', newTheme); + }; + + return ; +}; + +export default ThemeToggle; \ No newline at end of file