Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
Unable to render component when using Map as state type

I am fairly new to React. I was trying to create below component

const MyComponent = () => {
  const [data, setData] = useState<Map<string, MyData>>(new Map<string, MyData>())

  useEffect(() => {
    const parsedData: Map<string, MyData>> =
      JSON.parse(mockedData)
      setData(parsedData)
  }, [])

  return <>{data.size > 0 ? getDataComponents() : <></>}</>
}

As part of this, I am using mockedData to replicate the data I would receive from an API. This compiles correctly.

However at runtime, when the render cycle is triggered post effect, data.size is shown as undefined as data type is object instead of Map, due to which getDataComponents() is never triggered. I can also see the values on the object but not entirely certain what is causing it to be not identified as Map.

about 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!