Discussions

.map error

Image

 

Bonjour,

 

J'ai bien suivi le code du cours, pourtant j'ai une erreure dans la console qui m'empêche d'avancer au sujet du .map() dans DisplayedArticles.js

 

Voici l'erreure affichée:

Uncaught TypeError: Cannot read properties of undefined (reading 'map')

    at DiplayedArticles (DisplayedArticles.js:7:1)

    at renderWithHooks (react-dom.development.js:16305:1)

    at mountIndeterminateComponent (react-dom.development.js:20074:1)

    at beginWork (react-dom.development.js:21587:1)

    at HTMLUnknownElement.callCallback (react-dom.development.js:4164:1)

    at Object.invokeGuardedCallbackDev (react-dom.development.js:4213:1)

    at invokeGuardedCallback (react-dom.development.js:4277:1)

    at beginWork$1 (react-dom.development.js:27451:1)

    at performUnitOfWork (react-dom.development.js:26557:1)

    at workLoopSync (react-dom.development.js:26466:1)

    at renderRootSync (react-dom.development.js:26434:1)

    at performSyncWorkOnRoot (react-dom.development.js:26085:1)

    at flushSyncCallbacks (react-dom.development.js:12042:1)

    at flushSync (react-dom.development.js:26201:1)

    at Object.scheduleRoot (react-dom.development.js:27810:1)

    at react-refresh-runtime.development.js:284:1

    at Set.forEach (<anonymous>)

    at Object.performReactRefresh (react-refresh-runtime.development.js:263:

 

et le code de mon DisplayArticles.js:

import React from 'react';
import DisplayedArticle from './DisplayedArticle/DisplayedArticle'
import classes from './DisplayedArticles.module.css'

function DiplayedArticles(props) {

    let articles = props.articles.map(article => (
        <DisplayedArticle key={article.id} article={article} />
    ))

    return (
        <section className={classes.DisplayesArticles}>
            {articles}
        </section>
    );
}

export default DiplayedArticles
1 réponse
Image
Louis-Nicolas Leuillet
Le 27/12/2022 à 13:17

Hello Claire-lise

 

Ici vous avez un problème avec votre variables props.articles qui ne contient rien.

 

Avez-vous effectivement une propriété articles quand vous appelez le composant DiplayedArticles ? :)

Image
Inscrivez-vous ou connectez-vous pour participer à la discussion.

Informations

Créée le December 18, 2022 12:11 PM
Dernière activité le December 18, 2022 12:11 PM