I am new to TypeScript/React. I am getting an error for the following when trying to pass props as an array to a component.
I am calling the component as such:
return <ContactInfoBlock contactInfo={contact} />;
where contact is an array of information, eg:
const contact = {
contactName: 'Jim',
contactAvatar: 'jim.png',
contactEmail: '[email protected]',
contactPhone: '1234 4566',
};
And on my component file I have:
type ContactInfoInterface = {
contactName: string;
contactEmail: string;
contactPhone: string;
};
interface ContactInfoBlockProps {
contactInfo: ContactInfoBlock[];
}
const ContactInfoBlock = ({ contactInfo }: ContactInfoBlockProps) => {
return (
<Typography variant="h6">
{contactInfo.contactName}
</Typography>
//etc
This works - the data actually appears on the front end. But I get the warning:
Property 'contactName' does not exist on type 'ContactInfoInterface[]'. TS2339
According to the tutorials I've followed, this should work. But I still get the error.
Would anyone know what I could do?