1.0.4 • Published 1 year ago
blog-toc v1.0.4
blog-toc
Generate table of contents for article or blog posts quickly.
Usage/Examples
This package return a json object when you provide id.
import React, { useEffect, useState } from "react";
import { blogtoc } from "blog-toc";
function blogpage() {
const [toc, settoc] = useState();
var thetoc = blogtoc("theblogpage"); // change the id here
console.log(toc);
useEffect(() => {
settoc(thetoc);
}, []);
return (
<>
<div className="toc">
/* Here showing the table of contents */
<ul>
{toc?.map((elem, index) => {
return (
<>
<li key={index}>
<a href={elem.url}>{elem.heading}</a>
</li>
</>
);
})}
</ul>
</div>
<div id="theblogpage"> // id here
<h1>Hi from main page</h1>
<h2>this is h2</h2>
<h2>this is h3</h2>
</div>
</>
);
}
export default blogpage;
Authors
github - @Amanp30