Skip to main content
Version: 5.10.0



A react hook to manage state in a key value pair map.


npm install --save rooks

Importing the hook​

import { useMapState } from "rooks";


function Demo() {
const [
{ set, setMultiple, has, remove, removeMultiple, removeAll },
] = useMapState({ a: 1, b: 2 });
return null;

render(<Demo />);


Argument valueTypeDescriptionDefualt
initialValueObjectInitial value of the mapundefined


Returns an array of following items:

Return valueTypeDescription
mapanyvalue of the map
methodsObjectmethods to modify the map, see the table below

map methods:

Return valueTypeDescription
set(key: any, value: any) => voidset a key value pair in map
has(key: any) => booleanif key exists in map
setMultiple(...keys: any[]) => voidset multiple key value pair in map
remove(key: any) => voidremove a key value pair in map
removeMultiple(...keys: any[]) => voidremove multiple key value pair in map
removeAll() => voidremove all key value pair in map

Codesandbox Examples​

Basic Usage​

Join Bhargav's discord server​

You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.