Signed-off-by: Florian BOUILLON <f.bouillon@aptatio.com>
This commit is contained in:
4
src/components/Passthrough/Passthrough.astro
Normal file
4
src/components/Passthrough/Passthrough.astro
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
const json = JSON.stringify(Astro.props)
|
||||
---
|
||||
<script id="ASTRO_DATA" is:inline type="application/json" set:html={json}></script>
|
10
src/components/Passthrough/utils.ts
Normal file
10
src/components/Passthrough/utils.ts
Normal file
@ -0,0 +1,10 @@
|
||||
/**
|
||||
* note: you MUST only pass simple items that can go in JSON format natively
|
||||
*/
|
||||
export function load<T extends {} = {}>(): T {
|
||||
const tag = document.querySelector<HTMLScriptElement>('#ASTRO_DATA')
|
||||
if (!tag) {
|
||||
throw new Error('could not load client variables, tag not found')
|
||||
}
|
||||
return JSON.parse(tag.innerText)
|
||||
}
|
Reference in New Issue
Block a user