-
Mar 11th, 2021, 05:12 AM
#1
Thread Starter
Lively Member
ReactJS Unexpected Token and Adjascent JSX issue
Hi Guys,
First i want to ask if why am I getting an unexpected token ',' error in this code:
Code:
return (
<React.Fragment>
{Object.keys(data).length > 0 && Object.keys(data).map((telemetry, keys) => (
{
Object.values(data[telemetry]).map((listItem) => {
console.log()
})
}))
}
</React.Fragment >
)
Secondly, at some point I am getting an Adjacent JSX issue of my codes, mostly in this kind of structure:
Code:
return (
<React.Fragment>
</React.Fragment>
}
At some point I am avoiding some div, for some reason it affects the rendering inside of a grid. I just wanted a pure fragment of <Grid items> that I used for generating elements base on my json data.
Thank you
-
Mar 11th, 2021, 05:42 PM
#2
Re: ReactJS Unexpected Token and Adjascent JSX issue
I cannot speak specifically to ReactJS because I have only worked with JavaScript, jQuery, and Angular.
However, I do not think you have your Array map setup right. The callback parameters are:
- currentValue
- index (optional)
- array (optional)
But it looks like you're passing an array in the index parameter slot. Plus you're not really using it, so why even include it?
Finally, it looks like you're comparing the results of map. But when it goes to do the comparison, it compares if it is undefined, which it will never be because you have already confirmed that the array has items. I think you're wanting to compare if the array is empty, in which case you'd do:
Code:
Object.keys(data).length > 0 && Object.keys(data).map(key => { ... }).length
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|