I just dont get it. I am kinda new to Typescript but used to Code in React.js. I have a simple Component like
const Tab1: React.FC = () => {
const [spices, setSpices] = useState(
[
{
Gewuerz: "pepper",
Gramm: 50,
},
{
Gewuerz: "Tumeric",
Gramm: 870,
},
{
Gewuerz: "salt",
Gramm: 40,
},
{
Gewuerz: "muscat",
Gramm: 9,
}
]);
return (
<IonPage>
<IonHeader>
<IonToolbar>
<IonTitle class="ion-text-center">Spices</IonTitle>
</IonToolbar>
</IonHeader>
<IonContent>
<SpiceList spices={spices}/>
</IonContent>
</IonPage>
);
};
And a Child Component like
interface Props {
spices: Object[];
}
const SpiceList: React.FC<Props> = ({spices}: Props) => {
return (
<IonContent>
<IonList>
{spices.map((e) => <IonItem>{e.Gewuerz}</IonItem>)}
</IonList>
</IonContent>
)
};
export default SpiceList;
I want to render the different Spices inside Prop as a List. I can Map the Prop spices. But i cant access e.Gewuerz
as it says it is not available inside of e
. So how can i access the SubElements of spices?
EDIT: So it actually works like i tried it. But it always says "Compiled with Errors." If i dismiss it the app renders like i want it to.