samedi 12 septembre 2020

Passing Object as a props and using map() function on it in react js

While passing the object data as props to the component and looping through the data using the map() function.It gives an error that says TypeError: Cannot read property 'map' of undefined

import React from 'react'
import styles from './social.module.css';
import {Button, Typography, CardContent, CardActions, Card} from '@material-ui/core'
const SocialItem = ({
    Icon,
    title,
    mixed,
    red,
    blue,
    item
}) => {
    return (
        <Card className={styles.socialItem}>
            <CardContent>
                <Typography className={styles.socialItem__typo} variant="h4" component="h2">{title}</Typography>
                <Icon
                    className={`${styles.socialItem__Logo} ${mixed && styles.mixedInsta} ${blue && styles.blueFacebook} ${red && styles.redInsta}`}/>
                <div className={styles.desc}>
                    {item.map(itm => <li>{itm.price}</li>)}
                </div>
            </CardContent>
            <CardActions className=""></CardActions>
        </Card>
    )
}

export default SocialItem



Aucun commentaire:

Enregistrer un commentaire