samedi 30 novembre 2019

Im getting an undefined error in my proyect made with React

I am sending as a prop an array of objects. When i console.log(this.props) i get the array of objects, but when i try to assign it to a variable it gives me

TypeError:ninjas is undefined

import React from 'react';

class Ninjas extends React.Component {
    render(){
        const { ninjas } = this.props;
        const ninjasList = ninjas.map(ninja => {
            return(
                <div className="ninja" key={ ninja.key }>
                <div>Name: { ninja.name }</div>
                <div>Age: { ninja.age }</div>
                <div>Belt: { ninja.belt }</div>
                </div>
            )
        })
        return (
            <div className="ninja-list">
                { ninjasList }
            </div>
        );
    }
}

export default Ninjas;



Aucun commentaire:

Enregistrer un commentaire