Using Axios with react-chrono

392 views Asked by At

I am not able to get react chrono working when I tried to use the state data. I did a console log on conversationData and is it did print out and as well as conversationtracking. I did get an error that says: "Expected an assignment or function call and instead saw an expression". I am wondering where did I go wrong? here is the code of what I am trying to do:

const data = [
        conversationData.map(record => record.conversationtracking.map(items => {
            {
                {
                    title: moment(items.conversationdate).format('MMMM DD, YYYY')
                    cardTitle: items._id
                    cardSubtitle: items.name
                    cardDetailedText: items.text
                }
            }
        }))
    ];

    return (
        <div>
            <h1>sdvsdv</h1>
            <Chrono
                items={data}
                mode="VERTICAL"
            />
        </div>
    )
1

There are 1 answers

0
Anand G On BEST ANSWER

You needed return the data after map. Also you were missing , in your object defined inside the second map loop. PS: The way you are trying to double map the objects will impact the performance. You may need to find a better way to save that extra loop.

// As per the map structure, I hope the data is like this 
var conversationData = [{
  conversationtracking: [{
    _id: 1,
    name: 'AVC0',
    text: 'RESDS',
    conversationdate: '23/12/2020'
  }]
}]

const data = [
  conversationData.map(record => record.conversationtracking.map(items => {
    return {
      title: items.conversationdate, 
      cardTitle: items._id,
      cardSubtitle: items.name,
      cardDetailedText: items.text
    }
  }))
];
console.log(data)