Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 8eb9379

Browse files
Utterances에서 localStorage 다크모드여부를 확인해서 색을 결정하도록 변경
1 parent c26ffe1 commit 8eb9379

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

‎src/components/utterances/index.js‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
1-
import React, { useEffect } from 'react';
1+
import React, { createRef,useEffect,useRef } from 'react';
22

33
const src = 'https://utteranc.es/client.js';
44
const branch = 'master';
55

6-
export const Utterances = ({ repo, theme }) => {
7-
const rootElm = React.createRef();
6+
export const Utterances = ({ repo, path }) => {
7+
const rootElm = createRef();
8+
const isUtterancesLoaded = useRef(false);
89

910
useEffect(() => {
10-
if (!rootElm.current || rootElm.current.childNodes.length !== 0) return;
11+
if (!rootElm.current || isUtterancesLoaded.current) return;
12+
const storedIsDarkMode = localStorage.getItem('isDarkMode');
13+
1114
const utterances = document.createElement('script');
1215
const utterancesConfig = {
1316
src,
1417
repo,
1518
branch,
16-
theme: theme==='light'? 'github-light' : 'photon-dark',
19+
theme: JSON.parse(storedIsDarkMode)? 'photon-dark' : 'github-light',
1720
label: 'comment',
1821
async: true,
1922
'issue-term': 'pathname',
@@ -24,7 +27,8 @@ export const Utterances = ({ repo, theme }) => {
2427
utterances.setAttribute(configKey, utterancesConfig[configKey]);
2528
});
2629
rootElm.current.appendChild(utterances);
27-
}, [repo, rootElm, theme]);
30+
isUtterancesLoaded.current = true;
31+
}, [repo, rootElm, path]);
2832

2933
return <div className="utterances" ref={rootElm} />;
3034
};

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /