1

First of all sorry for my poor english, but i have a problem and i hope someone will can help me with it. When I look at my site on localhost or even the build, everything works perfectly, but when the site is deployed I get this error: Cannot read properties of undefined (reading 'map'). I do not understand why. The site is developed with React and Redux.

{questionsAndAnswers.map((q, index) => 
   <div key={q.id} className={"votre-question-card"} onClick={() => history.push(`/question/${q.id}`)}>
        <h3>Votre question {index + 1}</h3>
        <p>{dayjs(q.date).format("DD/MM/YYYY")}</p>

        {q.reponses.map((r, index) =>
            <div key={r.state} className={"votre-question-card-message"}>
                {r.state == 0 &&
                   <p>1 nouveau message</p>
                }
            </div>
        )}
           <button className={"votre-question-card-button"}><img src={discuter}/>Voir la réponse</button>
    </div>
)}

What works locally but not in production is {q.reponses.map((r, index) =>

QuestionsAndAnswers returns an array containing objects an arrays of objects

console.log of questionsAndAnswers :

Array (5)
  0 Object
    content: ""
    date: "2022-02-17 14:41:29"
    dateClosed: "0000-00-00 00:00:00"
    id: "10"
    idUser: "3499"
    listReponses: [] (0)
    reponses: Array (2)
       0 {id: "16", idQuestion: "10", idCareManager: "0", date: "2022-02-18 12:10:50", state: "1", …}
       1 {id: "6", idQuestion: "10", idCareManager: "2", date: "2021-12-01 11:44:10", state: "1", …}

  1 {id: "11", idUser: "3499", date: "2022-02-21 10:54:06", dateClosed: "0000-00-00 00:00:00", state: "0", …}
  2 {id: "12", idUser: "3499", date: "2022-02-23 16:07:37", dateClosed: "0000-00-00 00:00:00", state: "0", …}
  3 {id: "13", idUser: "3499", date: "2022-02-23 16:44:48", dateClosed: "0000-00-00 00:00:00", state: "0", …}

Thank you for your precious help !

solene
  • 21
  • 4
  • in that case `q.reponses` is `undefined` - confirm using console.log – Bravo Mar 01 '22 at 09:15
  • Either `questionsAndAnswers` or `q.reponses` on one of the questions is `undefined`. We can't debug that for you, you'll need to do so using the debugger built into your IDE and/or browser. Re your `console.log`: Beware of [this issue](http://stackoverflow.com/questions/38660832/element-children-has-elements-but-returns-empty-htmlcollection). Instead of stumbling around in the dark with a`console.log` torch, I suggest *turning on the lights* using your debugger. [More here](https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems). – T.J. Crowder Mar 01 '22 at 09:18
  • the problem is that everything works locally, so q.reponses is defined, and returns the expected object. – solene Mar 01 '22 at 09:33
  • about the debugger, I am not sure I can debug a build, the online file is the build of my project – solene Mar 01 '22 at 09:34
  • and I am not the responsible person of the deployment, so I can't ask to this person to launch it online after each correction. In fact I am above all searching a way to reproduce this bug locally to debug it before to push in production – solene Mar 01 '22 at 09:35
  • When I debug I find the problem on the q.reponses.map. Q return an array containing reponses, wich is also an array, maybe the problem is there ? – solene Mar 02 '22 at 08:26

0 Answers0