Results 1 to 2 of 2

Thread: ReactJS Unexpected Token and Adjascent JSX issue

  1. #1

    Thread Starter
    Lively Member FunkySloth's Avatar
    Join Date
    Aug 2016
    Posts
    89

    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

  2. #2
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Location
    South Louisiana
    Posts
    10,484

    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
    "Code is like humor. When you have to explain it, itís bad." - Cory House
    VbLessons | Code Tags | Sword of Fury - Jameram

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width