DEV Community

Ali Dauda
Ali Dauda

Posted on

making using ref work with typescript

was just wondering how i can make this typed
` function getMap() {
if (!ref.current) {
// Initialize the Map on first usage.
ref.current = new Map();
}
return ref.current;
}

ref={(node)=>{
const map = getMap();
if(!map)return;
if (node) {
map.set(cat.id, node);
} else {
map.delete(cat.id);
}

      }}
Enter fullscreen mode Exit fullscreen mode

`
i am trying to make the getMap() fucntion to be typed but i have no idea how

Top comments (0)