Add new post toc

fix useLayoutEffect warnning
This commit is contained in:
DefectingCat
2022-08-11 18:06:26 +08:00
parent 39c5711e75
commit 77c01e168d
7 changed files with 71 additions and 23 deletions

View File

@ -0,0 +1,29 @@
import { useEffect, useState } from 'react';
import tocbot from 'tocbot';
const SlideToc = () => {
const [mounted, setMounted] = useState(false);
useEffect(() => setMounted(true), []);
useEffect(() => {
// Waiting the right time.
mounted &&
tocbot.init({
tocSelector: '.toc',
contentSelector: '#post-content',
headingSelector: 'h1, h2, h3',
});
return () => tocbot.destroy();
}, [mounted]);
return (
<>
<div className="flex justify-end">
<div className="toc"></div>
</div>
</>
);
};
export default SlideToc;