I have a bunch of NextJS components such as this one:
"use client";
type Props = {
title: string;
subtitle: string;
};
export default function HeaderComponent(props: Props) {
return (
<div>
<h1>{props.title}</h1>
<h2>{props.subtitle}</h2>
</div>
);
}
I am trying to find a way to extract the component props in run-time to an array of names. in the case above I'm looking to get the response of:
["title", "subtitle"]
I thought I can achieve this by following the NextJS docs on lazy loading and dynamic components but so far ended up with ComponentPropsType without knowing how to convert it to an array of strings. what I have so far is:
const Component = dynamic(() => import("../components/header"), {
ssr: false,
loading: (lodaingProps) => {
return <p>Loading...</p>;
},
});
type ComponentPropsType = React.ComponentProps<typeof Component>;
Can someone please direct me on the right way to do this? at this point I'm not even sure this is feasible. based on some readings I found that this type of data may not even available in run-time. is that true?
Aucun commentaire:
Enregistrer un commentaire