@omer_bhatti/react-keys
v1.0.1
Published
This module is used to automatically increment a number generally used for key in react apps
Downloads
3
Maintainers
Readme
Installation
npm i @omer_bhatti/react-keys
Usage
import KeyGenerator from '@omer_bhatti/react-keys'
import React from 'react'
export default function index() {
const data = ["item1", "item2", "item3", "item4", "item5"];
return (
<div>
{
data.map((item) => (
<div key={KeyGenerator.getKey()}>
{item}
</div>
))
}
<div/>
)
}
Functions
increment() - Increments the key
getKey() - Returns the current key and increment the key
getHashKey() - Returns the key as Hashed String and increment the key
setkey(value) - sets the key to new value
reset() - resets the key to 0
getNextKey() - returns the next key
getPreviousKey() - returns the previous key
Bugs
if you face any issue like SyntaxError: Cannot use import statement outside a module just add this to your packages.json file
{
"type": "module"
}