I am a new learner of React-Native. I am trying to map data into View. Have been trying to solve this, read through the documentation and other resources but couldn't succeed. What Am I doing wrong here?
DATA
const data = [
{
id: "1",
title: "Online Appointment",
body: "Select the specialist and make an appointment through our App!",
image: "../../../assets/images/intro1.png",
},
{
id: "2",
title: "Emergency Call",
body: "Just In One Click Our Quick Response Team Will Provide You First Aid!",
image: "../../../assets/images/intro2.png",
},
{
id: "3",
title: "Online Pharmacy",
body: "You Can Buy and Sell Medical Equipments Through Our App!",
image: "../../../assets/images/intro3.png",
},
]
I am using these data to map here:
{data.map((id, title, body, image) => {
return (
<View style={TOPCOLUMN} key={id}>
<ImageBackground source={{ uri: image }} style={INTROIMAGE}>
<Text style={TITLE}>{title}</Text>
<Text style={CONTENT}>{body}</Text>
</ImageBackground>
</View>
)
})}
The error I am getting
Argument of type '(id: any, title: any, body: any, image: any) => Element' is not assignable to parameter of type '(value: { id: string; title: string; body: string; image: string; }, index: number, array: { id: string; title: string; body: string; image: string; }[]) => Element'.
CodePudding user response:
you forgot to destruct
{data.map((id, title, body, image) => {
should be
{data.map(({id, title, body, image}) => {