mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-24 14:36:59 +02:00
refactor(v2): toggle data-theme with vanilla js instead of react helmet (#2127)
* refactor(v2): toggle data-theme with vanilla js instead of react helmet * use document documentElement
This commit is contained in:
parent
ee00ecf569
commit
33622c5347
4 changed files with 114 additions and 116 deletions
|
@ -9,9 +9,14 @@ import * as React from 'react';
|
|||
const useTheme = () => {
|
||||
const [theme, setTheme] = React.useState(
|
||||
typeof document !== 'undefined'
|
||||
? document.querySelector('html').getAttribute('data-theme')
|
||||
? document.documentElement.getAttribute('data-theme')
|
||||
: '',
|
||||
);
|
||||
|
||||
React.useEffect(() => {
|
||||
document.documentElement.setAttribute('data-theme', theme);
|
||||
}, [theme]);
|
||||
|
||||
React.useEffect(() => {
|
||||
try {
|
||||
const localStorageTheme = localStorage.getItem('theme');
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue