Failed to compile (react javascript)

254 Views Asked by At

this is my problem i hope there is a solution

./src/LineGraph.js
Syntax error: D:/programming/corona-tracker-app/covid-19-tracker/src/LineGraph.js: Unexpected token (88:12)

  86 |   return (
  87 |     <div>
> 88 |       {data?.length > 0 && (
     |             ^
  89 |         <Line
  90 |         options={options}
  91 |           data={{

code 1 code 2

1

There are 1 best solutions below

0
Danial On BEST ANSWER

Based on you images of code, you handle null-safety (or having values) with a Typescript operator : ?.

And when you define data object using useState in line 67, assigned an empty object.

The LineGraph component ran and it rendered with an empty object, If you want to check if data has values, this may helps you:

Object.keys(data).length

So:

return(
<div>
    {Object.keys(obj).length === 0 && (
        <Line 
        // options
        />
    )}
</div>
)