I have this DB, and I'm trying correctly map the types when using Map function. First time doing it so trying to learn but I'm stuck.
Db
const db = {
data: [
{
id: 1,
contentType: ['video'],
title: '1 to 1 Coaching: Sprinting Technique',
author: {
name: 'James',
image: {
alt: 'smiling.',
},
},
image: {
alt: 'Two footballers jostling for the ball with a coach watching in the background.',
},
},
],
}
For now I'm just using sample type of id and title but even here I'm stuck on how to correctly map it so TS does not complain :(
App.tsx
type Data = {
id: number
title: string
}
interface Customer {
id: number
title: string
}
export default function Box(): JSX.Element {
const [data, setData] = useState([db])
return (
<>
{data.map(
({
data: {
id,
contentType,
title,
author: {
name,
img: { src, alt },
},
image: { src, alt },
},
}): JSX.Element => {
console.log(id)
return <div css={mainBox}></div>
},
)}
</>
)
}
data[x].author.imagein your db, but adata[x].author.imginBox().