What would be the solution for applying the attached stylesheets on the checkbox ::before{} pseudoelement when it's checked? As soon as I have supplied the checked={checked} property, the attached stylesheets shop working
export const ThemeSwithcer: FC = () => {
const [checked, setChecked] = useState(false);
useEffect(() => {
if (localStorage.getItem('theme') === 'theme-dark') {
setTheme('theme-dark');
setChecked(false);
} else {
setTheme('theme-light');
setChecked(true);
}
}, [checked]);
const setTheme = (themeName: string) => {
localStorage.setItem('theme', themeName);
document.documentElement.className = themeName;
}
const themeChangeHandler = (e: React.ChangeEvent<HTMLInputElement>) => {
if (localStorage.getItem('theme') === 'theme-dark') {
setTheme('theme-light');
} else {
setTheme('theme-dark');
}
}
return (
<label className="Theme-Switcher">
<input className="Theme-Switcher-Util" type="checkbox" onChange={themeChangeHandler} checked={checked} />
<span className="Theme-Switcher-Slider round"></span>
</label>
);
}
&:checked + .Theme-Switcher-Slider:before {
-webkit-transform: translateX(24px);
-ms-transform: translateX(24px);
transform: translateX(24px);
background: white url('https://i.ibb.co/7JfqXxB/sunny.png');
background-repeat: no-repeat;
background-position: center;
}