Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ryanhefner/use-ref-map

🪝 Dynamically generate and reference React reference instances with this handy hook.
https://github.com/ryanhefner/use-ref-map

Last synced: 21 days ago
JSON representation

🪝 Dynamically generate and reference React reference instances with this handy hook.

Awesome Lists containing this project

README

        

# 🪝 use-ref-map

[![npm](https://img.shields.io/npm/v/use-ref-map?style=flat-square)](https://www.pkgstats.com/pkg:use-ref-map)
[![NPM](https://img.shields.io/npm/l/use-ref-map?style=flat-square)](LICENSE)
[![npm](https://img.shields.io/npm/dt/use-ref-map?style=flat-square)](https://www.pkgstats.com/pkg:use-ref-map)

Dynamically generate and reference React reference instances with this handy hook.

## Install

Via [npm](https://npmjs.com/package/use-ref-map)

```sh
npm install use-ref-map
```

Via [Yarn](https://yarn.pm/use-ref-map)

```sh
yarn add use-ref-map
```

## How to use

```
import useRefMap from 'use-ref-map`

const ExampleComponent = ({ buttonData }) => {
const { getRef, setRef } = useRefMap()

const handleSubmit = (evt) => {
evt.preventDefault()

const email = getRef('email_input')?.current?.value
const password = getRef('password_input')?.current?.value
}

return (




)
}
```
_This is a silly example, but should give you an idea of how to use this hook. This is most useful when dealing with an array of components that require unique `ref` instance props passed to each, using an example key of something like, `dynamic-ref-${id}`._

## License

[MIT](LICENSE) © [Ryan Hefner](https://www.ryanhefner.com)