Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

389
Views
Anchor links not working in Next.JS that are dynamically generated

I wrote an algorithm to parse and generate table of contents based on my markdown files. The table of contents output from markdown is raw HTML strings that I set using setDangerouslyInnerHTML.

  • Table of Contents library I made here

Snippet

const TableOfContents = ({ toc }) => {
  return (
    <div className={post["toc"]}>
      <h2>Table of Contents</h2>
      <div dangerouslySetInnerHTML={{ __html: toc }}></div>
    </div>
  );
};

The problem is, the standard href links on the li elements are not triggering anchor tag movements on the page.

The headers on the page have an id like <h1 id="test>.. and the corresponding

<li><a href="#test">test</a></li> doesn't trigger the navigation. Looking online, I know <Link> is recommended, but my generation is dynamic and all I do is interpolate the string into the page, so I haven't figured out a way to have any fancy JSX or function invocation embedded into the string. However, I'm still confused why the standard HTML clicking would not work?

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!