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.