Looking to implement a custom Dark Mode feature for a specific element on my create-react-app website using MUI. I have successfully implemented the Switch to change the state on toggle, but I am having trouble figuring out how to toggle it back and forth. I basically want the page to switch to dark mode when toggled and revert back to light mode with the same toggle button. Any suggestions would be appreciated.
import React from 'react'
import Switch from '@mui/material/Switch';
const DarkMode = () => {
const [color, setColor] = React.useState(false)
return (
<div style={{ backgroundColor: color ? '#2c2d30' : '#ffffff' }}>
<Switch onChange={setColor} />
<h1 style={{ color: color ? '#ffffff' : '#000000' }}>Hello welcome to my site</h1>
</div>
)
}
export default DarkMode