#How to get persistent variables for a component

5 messages · Page 1 of 1 (latest)

trim siren
#

--- Is the question visible?

void oracle
#

Node.js modules are singletons by default. I would put the constructor call in a separate .ts/.js file and then just import the slugger in each frontmatter. This will automatically give you the same instance of the object

// slugger.ts
const slugger = new GithubSlugger();
export default slugger;

// Component.astro
---
import slugger from "path/to/slugger.ts";
---

<h1 id={slugger.slug("abc")}>ABC</h1>
trim siren
#

got it, ty!

void oracle
#

No worries 🙂