So, I want to create a component which will create some inputs, needed for creating an entity in the back-end.
For this, I have two ideas:
1st
Create a component which takes a type as a prop
Pass the type to the prop
Iterate over its keys
For each key, create an input
For this approach, my component looks like this:
import { Type } from "typescript";
type Props = {
dataType: Type
}
export default function CreateRow(props: Props) {
return (
<div>//iteration over keys</div>
);
}
and the component would be called like this:
import type {EducatieItem} from './EducatieItem';
<CreateRow dataType={EducatieItem}/>
but this doesn't work. I get
'EducatieItem' only refers to a type, but is being used as a value here.
EducatieItem is
export type EducatieItem = {
id: string,
name: string
};
The other idea was to create a generic component, like this:
export default function CreateRow<T>() {
return (
<div>//iteration over keys</div>
);
}
and the call:
<CreateRow<EducatieItem>/>
this doesn't throw any error... yet.
If I actually try to iterate over the keys of T, then I will get the same error as before.
Is there any way to achieve what I want? Are any of my approaches valid though?
Thanks.