Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Dark Mode feature #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ishi142005
Copy link

Added a Dark Mode feature by adding DarkMode.js.
Darkmode.js:-
import React, { useEffect, useState } from 'react';

const DarkMode = () => {
// Initialize state from localStorage
const [theme, setTheme] = useState(localStorage.getItem('theme') || 'light');
// Set the theme on page load
useEffect(() => {
document.documentElement.setAttribute('data-theme', theme);
}, [theme]);
// Toggle the theme between dark and light
const toggleTheme = () => {
const newTheme = theme === 'dark' ? 'light' : 'dark';
setTheme(newTheme);
localStorage.setItem('theme', newTheme);
};
return (

Toggle Dark Mode

);
};
export default DarkMode;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant