#trying to wrap my head around const { title } = Astro.props;
4 messages · Page 1 of 1 (latest)
const { title } = Astro.props
is called deconstructing and is equivalent to:
const title = Astro.props.title
You can type your props by doing:
type Props = {
title: string
}
const { title } = Astro.props
or
interface Props {
title: string
}
const { title } = Astro.props
You can use title?: string to make the prop optional.
By typing your props, you'll get intellisense when you use your component and red-squiggles if you use an invalid prop.
thank you for laying that out for me
to make sure I understood, I can define:
type Props = {
title: '- website name'
}
const { title } = Astro.props
and then pass it like
<title>Contact {title}</title>
and if I were to have like a Header.astro with all my meta tags and stuff if I include
type Props = {
title: '- website name'
}
const { title } = Astro.props
in the codefence and have <Header /> in my page layout it'll be included in all pages or do i have to reapply the statement to all codefences on pages?