Reputation: 47
I need to initialize an array of objects in my state in react Ts. The array should look somewhat like this
addressBook[
details{
name:"Tom"
mail: "[email protected]"
mobile: "1111111111"
}
]
I need to create an array of objects like this which will contain multiple contacts with their details.
Upvotes: 1
Views: 926
Reputation: 11156
Define an interface:
interface Detail {
name: string;
mail: string;
mobile: string;
}
Then in component definition:
const DetailPage = (): ReactElement => {
const [details, setDetails] = useState<Detail[]>([]);
return ( . . . );
};
Upvotes: 2