Skip to content
/ useToc Public

A ReactJs custom-hook for generating table-of-content data.

License

Notifications You must be signed in to change notification settings

webiya/useToc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

useToc

Create easy to use data for building table of content for you react component.

🚧 Under development 🚧

Installation

npm i use-toc

or

yarn add use-toc

Usage Example

import Toc from './components/Toc';
import useToc from 'use-toc';

export default function App() {
  const toc = usesToc(".container h3");
  // toc = [ {id:"",text:""}, {id:"",text:""}, ...]
  return (
    <div className="App">
      <Toc tocData={toc} />
      <div className="container">
        <h3 id="one">
          Section
          <span role="img" aria-label="imoji">
            🦁
          </span>
        </h3>
        <p>
          Huh? We do now. I'll get it back to you, alright? Yeah. This is it.
          This is the answer. It says here that a bolt of lightning is gonna
          strike the clock tower precisely at 10:04 p.m. next Saturday night.
        </p>
      
        ...
    
    </div>  
  )
}

Demo

Sand Box


About

A ReactJs custom-hook for generating table-of-content data.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published