0

I use node js + React. I have data that cames from mongoose which usually have this format:

{
  "_id": "61b711721ad6657fd07ed8ae",
  "url": "/esports/match/natus-vincere-vs-team-liquid-14-12",
  "dataInfo1param1": [
    [
      {
        "oddTitle": "Winner",
        "odddTitle": "FadeGaming | okura",
        "oddvalue": "2.58 | 1.48 | 13 09:28:12//2.71 | 1.44 | 13 12:25:37"
      }
    ]
  ]
}

In MatchCard.js component I have correctly passed match data from my node js router, but I can't output it on react page. Here component code

import React from 'react';

export const MatchCard = ({ match }) => {
  return (
    <div>
      <p>{match.url}</p>
      <p>{match.dataInfo1param1}</p>
    </div>
  );
};

match.url value outputs correctly. But match.dataInfo1param1 throw error Error: Objects are not valid as a React child (found: object with keys {oddTitle, odddTitle, oddvalue}). If you meant to render a collection of children, use an array instead.

I tried to output { match.dataInfo1param1['oddTitle'] } but it show empty value...

So the question is how to output array key values for both oddTitle and oddvalue? Maybe I should map them and then render them in a different way?

Thanks

1 Answer 1

1

since dataInfo1param1 is an array , you can access the value oddTitle like this

{ match.dataInfo1param1[0][0].oddTitle }

Remove one [0] if the above line doesn't work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.