Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

ReactJS TaildwindCSS – darkMode is always set to true

I’m using TailwindCSS in React app and i’m trying to make dark mode using Tailwind, but bg is already set to dark even though value is false.

import React, { useState } from 'react';

const App = () => {

    const [darkTheme, setDarkTheme] = useState(false);

    return (<div className= {darkTheme ? 'dark' : ''}>
            <div className="bg-gray-100 dark:bg-gray-900">
              App
            </div>
        </div>);

};

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You are likely using the wrong darkmode toggle setting in tailwind.config.js. By default, the tailwind.config.js is setup to use CSS’s prefers-color-scheme. You want to manually toggle dark and light mode in your code.

Set darkMode: 'class' in order to toggle darkmode via your class name.

https://tailwindcss.com/docs/dark-mode

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading