I just want to pass contactList which is an array of objects as a prop to ContactList component, but I’m having the error
Property 'contactList' does not exist on type 'IntrinsicAttributes'.ts(2322)
I’m new to typescript and I’ve been stuck for hours already, please help thank you!
import { useState } from "react";
import ContantList from "./ContantList";
function ContactForm() {
interface Contact {
name: string;
email: string;
}
const [contactList, setContactList] = useState<Contact[]>([]);
function onAddContact(event: React.FormEvent<HTMLFormElement>): void {
event.preventDefault();
const formData = new FormData(event.currentTarget);
const name = formData.get("name") as string;
const email = formData.get("email") as string;
setContactList((prevData) => [...prevData, {name: name, email: email}])
}
return (
<form onSubmit={onAddContact}>
<h1 className="ml-5 mt-10">Contact Registration Form</h1>
<label className="mb-1 ml-5 mt-5 inline-block" htmlFor="name">
Name
</label>
<input className="ml-5 block" type="text" name="name" id="name" />
<label className="mb-1 ml-5 mt-5 inline-block" htmlFor="email">
Email
</label>
<input className="ml-5 block" type="email" name="email" id="email" />
<button type="submit"
className="mb-1 ml-5 mt-5 border bg-[#ddd] p-2 text-white"
>
Add
</button>
<section className="mt-5 bg-[#FFFFFF] p-5" id="Contacts">
CONTACTS
<ul className="mt-5 list-none p-5">
<ContantList contactList={contactList}/> // Property 'contactList' does not exist on type 'IntrinsicAttributes'.ts(2322)
</ul>
</section>
</form>
);
}
export default ContactForm;
2
Answers
After a couple more minutes searching, I finally found the solution from here
Probably the problem is in your ContactList props, it must have one parameter