Add the dependency:
npm install @redredgroup/react-browser-theme-detectyarn add @redredgroup/react-browser-theme-detectImport the package:
import{isTheme,isThemeLight,isThemeDark}from"@redredgroup/react-browser-theme-detect";Returns the String value for dark mode or light mode:
constthemeString=isTheme();// Returns "light" or "dark"When the Boolean value for dark mode detection is required,
constisDark=isThemeDark();// If it is in dark mode, return true or falseconstisLight=isThemeLight();// If it is in dark mode, return true or falseThis package only works in browsers that natively support @media (prefers-color-scheme), so it just returns "light" in unsupported browsers. Current browser support
