@mantine/hooks
Version:
A collection of 50+ hooks for state and UI management
27 lines (26 loc) • 773 B
JavaScript
"use client";
import { useForceUpdate } from "../use-force-update/use-force-update.mjs";
import { useRef } from "react";
//#region packages/@mantine/hooks/src/use-map/use-map.ts
function useMap(initialState) {
const mapRef = useRef(new Map(initialState));
const forceUpdate = useForceUpdate();
mapRef.current.set = (...args) => {
Map.prototype.set.apply(mapRef.current, args);
forceUpdate();
return mapRef.current;
};
mapRef.current.clear = (...args) => {
Map.prototype.clear.apply(mapRef.current, args);
forceUpdate();
};
mapRef.current.delete = (...args) => {
const res = Map.prototype.delete.apply(mapRef.current, args);
forceUpdate();
return res;
};
return mapRef.current;
}
//#endregion
export { useMap };
//# sourceMappingURL=use-map.mjs.map