Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
use-system-theme
Advanced tools
React Hook for System Theme (User preferred color scheme). Please use React > 16.8.0
for React Hooks support.
It detects the system theme and will update right after the users change the theme.
yarn add use-system-theme
or
npm install --save use-system-theme
import React from 'react'
import useSystemTheme from 'use-system-theme'
export default () => {
const systemTheme = useSystemTheme()
return <div>The System Theme is: {systemTheme}</div>
}
As 2019 December, all major browsers on both mobile and desktop platforms support the prefers-color-scheme media query
feature. For more details, please check:
https://caniuse.com/#feat=prefers-color-scheme
The useSystemTheme
function has only one argument isSSR
, and you must pass true
for SSR app. Otherwise, your app may have bug like doesn't show dark them on dark theme devices.
declare const useSystemTheme: (isSSR?: boolean) => SystemTheme
import React from 'react'
import useSystemTheme from 'use-system-theme'
export default () => {
const systemTheme = useSystemTheme(true)
return <div>The System Theme is: {systemTheme}</div>
}
To support SSR (server side rendering), the initial theme will be always light
(since we don't know the theme on the server side) and it would immediately become dark
if the device's theme is dark
. Unfortunately, we can't avoid this because of the React hydrate:
React expects that the rendered content is identical between the server and the client.
So that for all SSR app, the initial screen will be light
and become dark
immediately on dark theme devices. It's caused by the nature of how React SSR works.
yarn start
To build the library and watch the file changes locally.
The local examples use the yalc to get live local version library.
You need to run yarn watch:yalc
on the root directory during development. And use npx yalc add use-system-theme
in the example directory under examples/
. Then follow the README file in each example folder.
Note: the yalc
will change the pcakge.json
for the example project to "use-system-theme": "file:.yalc/use-system-theme"
. Please do NOT commit the change because it would cause CI/CD failure.
MIT © xcv58
FAQs
React Hook for System Theme
The npm package use-system-theme receives a total of 0 weekly downloads. As such, use-system-theme popularity was classified as not popular.
We found that use-system-theme demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.