JSI guess change this line const [theme, setTheme] = useState(localStorage.getItem('theme')); Because while refreshes it overrides the local storageComment·Article·Jun 12, 2022·Add dark mode to your React application with TailwindCSS