0.1.7 • Published 2 years ago

@flowsn4ke/usekeys v0.1.7

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

useKeys

Generate unique yet persisted keys for .map() functions in React, allowing React to update only the components that need to be and preventing duplicate keys that lead to bugs. The function it returns accepts the array index as an argument.

Note

You need one instance of useKeys() per .map() function call, otherwise you'll end up with duplicates.

Usage

import useKeys from '@flowsn4ke/usekeys'

export function MyComponent(props) {
  const k = useKeys()

  return <>
  {new Array(42).fill(null).map(value, i) => {
    return <div key={k(i)}>
    unique key number {i}: {k(i)}
    </div>}}
  </>
}
0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago