File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { useTheme } from 'next-themes'
2- import React , { useEffect , useState } from 'react'
2+ import React , { useState } from 'react'
33import ReactMarkdown from 'react-markdown'
44import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter'
55import { a11yDark as dark , prism as light } from 'react-syntax-highlighter/dist/cjs/styles/prism'
@@ -66,15 +66,11 @@ const Code: CodeComponent = ({
6666 children = '' ,
6767 ...properties
6868} ) => {
69- const { theme, setTheme } = useTheme ( )
69+ const { theme} = useTheme ( )
7070 const [ copied , setCopied ] = useState ( false )
7171 const match = / l a n g u a g e - ( \w + ) / . exec ( className || '' )
7272 const isCodeBlock = Boolean ( match ) || String ( children ) . includes ( '\n' )
7373
74- useEffect ( ( ) => {
75- setTheme ( theme ! )
76- } , [ setTheme , theme ] )
77-
7874 const handleCopy = async ( ) => {
7975 const text = String ( children ) . replace ( / \n $ / , '' )
8076 try {
Original file line number Diff line number Diff line change 11import { useTheme } from 'next-themes' ;
2- import { useEffect } from 'react' ;
2+ import { useEffect , useRef } from 'react' ;
33import SakanaWidget from 'sakana-widget' ;
44import 'sakana-widget/lib/index.css' ;
55
66const Sakana = ( ) => {
77 const { theme } = useTheme ( ) ;
8+ const widgetRef = useRef < SakanaWidget | null > ( null ) ;
89
910 useEffect ( ( ) => {
10- new SakanaWidget ( {
11+ widgetRef . current ?. unmount ( ) ;
12+
13+ const widget = new SakanaWidget ( {
1114 character : Math . random ( ) < 0.6 ? 'takina' : 'chisato' ,
1215 controls : false ,
1316 stroke : { color : theme === 'dark' ? '#333333' : '#e6e6e6' } ,
1417 } ) . setState ( { i : 0.001 , d : 1 } ) . mount ( '#sakana-widget' ) ;
18+
19+ widgetRef . current = widget ;
20+
21+ return ( ) => {
22+ widget . unmount ( ) ;
23+ widgetRef . current = null ;
24+ } ;
1525 } , [ theme ] ) ;
1626
1727 return (
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import { fetchPosts, fetchUser } from '../lib';
55import genRSS from '../lib/rss' ;
66
77import { useTheme } from 'next-themes' ;
8+ import { useEffect } from 'react' ;
89
910import Image from 'next/image' ;
1011
@@ -27,7 +28,9 @@ export const getStaticProps: GetStaticProps = async () => {
2728const Index : NextPageWithLayout < { posts : Post [ ] ; user : User } > = ( { posts, user } ) => {
2829 const { setTheme } = useTheme ( ) ;
2930
30- if ( process . env . theme !== 'both' ) setTheme ( process . env . theme || 'dark' ) ;
31+ useEffect ( ( ) => {
32+ if ( process . env . theme !== 'both' ) setTheme ( process . env . theme || 'dark' ) ;
33+ } , [ setTheme ] ) ;
3134
3235 return (
3336 < div >
You can’t perform that action at this time.
0 commit comments