#Can't access props computed from a layout

1 messages · Page 1 of 1 (latest)

lilac seal
#

Hello, really basic question I guess but I can't seem to access a prop computed in a layout:

const { content, frontmatter, ...props} = Astro.props;
props.version = currentVersion || latestVersion;

When I console.log or place <Debug {props.version}/> in the layout, I get the correct version number, but if I try to access {props.version} or {version} in the MDX it's either empty or not defined.

What's the proper way of doing this? Can it be done via a layout and not a component?

Thanks.

fathom adder
#

I am not the deep-down JS expert, but I assume the ...props decomposition gives you a new object, that is known nowhere, except in your layout. TL;DR: You need to set the version somewhere on your MDX object, either the frontmatter (probably the best solution) or on the content.

lilac seal
#

I've derived the version from folder names. I was trying to pass this info to MDX files. It's not ideal I know; maybe I can pass this to the frontmatter.

fathom adder
#

That should work.