Skip to content

Commit

Permalink
fix(v2): useTOC hooks should not be called in each nested children (#…
Browse files Browse the repository at this point in the history
…1959)

* fix(v2): useTOC hooks should not be called in each nested children

* fragment

* rename -> DocTOC
  • Loading branch information
endiliey authored and yangshun committed Nov 11, 2019
1 parent 9e290c9 commit 5e445a0
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions packages/docusaurus-theme-classic/src/theme/DocItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@ const LINK_CLASS_NAME = 'contents__link';
const ACTIVE_LINK_CLASS_NAME = 'contents__link--active';
const TOP_OFFSET = 100;

function Headings({headings, isChild}) {
function DocTOC({headings}) {
useTOCHighlight(LINK_CLASS_NAME, ACTIVE_LINK_CLASS_NAME, TOP_OFFSET);
return (
<div className="col col--3">
<div className={styles.tableOfContents}>
<Headings headings={headings} />
</div>
</div>
);
}

function Headings({headings, isChild}) {
if (!headings.length) return null;
return (
<ul className={isChild ? '' : 'contents contents__left-border'}>
Expand Down Expand Up @@ -55,7 +64,7 @@ function DocItem(props) {
const metaImageUrl = siteUrl + useBaseUrl(metaImage);

return (
<div>
<>
<Head>
{title && <title>{title}</title>}
{description && <meta name="description" content={description} />}
Expand Down Expand Up @@ -155,17 +164,11 @@ function DocItem(props) {
</div>
</div>
</div>
{DocContent.rightToc && (
<div className="col col--3">
<div className={styles.tableOfContents}>
<Headings headings={DocContent.rightToc} />
</div>
</div>
)}
{DocContent.rightToc && <DocTOC headings={DocContent.rightToc} />}
</div>
</div>
</div>
</div>
</>
);
}

Expand Down

0 comments on commit 5e445a0

Please sign in to comment.