# @mrii/react-proxy-ref

> A simple package to create one ref for multiple elements.

Latest version **1.0.4** (published 2024-04-06) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @mrii/react-proxy-ref
pnpm add @mrii/react-proxy-ref
yarn add @mrii/react-proxy-ref
bun add @mrii/react-proxy-ref
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2024-04-06 |
| First published | 2023-04-09 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Abd Ul-Hameed Maree |
| Maintainers | abd-ulhameed-maree |
| Keywords | front-end, react, react-hooks, hooks, react-ref, ref, proxy, proxy-ref, utils, utility |

## Links

- npm: https://www.npmjs.com/package/@mrii/react-proxy-ref
- Repository: https://github.com/AbdUlHamedMaree/react-proxy-ref
- Issues: https://github.com/AbdUlHamedMaree/react-proxy-ref/issues
- npm.io page: https://npm.io/package/@mrii/react-proxy-ref

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 1.0.4 (latest) — 2024-04-06
- 1.0.0 — 2023-04-09
- 0.0.1 — 2023-04-09

## README

# @mrii/react-proxy-ref

A simple package to create one ref for multiple elements.

if you have a case where you need to create a large/dynamic number of refs, this package is the best fit for it.

it'll exports a hook that will create a proxy object, so you can assign multiple refs to it.

## Installation

```bash
# yarn
yarn add @mrii/react-proxy-ref

# npm
npm i @mrii/react-proxy-ref
```

## Usage

```tsx
import type React from 'react';
import { useProxyRef } from '@mrii/react-proxy-ref';

export const Component: React.FC = () => {
  const proxyRef = useProxyRef<HTMLInputElement | null>(
    null /* defaultValue, optional, default to `null` */
  );

  const way1 = () => {
    // use the refs if you know the names
    proxyRef.email.current?.value;
    proxyRef.password.current?.value;
  };

  const way2 = () => {
    // get all the refs if it's dynamic
    const refs = Object.values(proxyRef);

    refs.forEach(ref => {
      ref.current?.value;
    });
  };

  return (
    <>
      <input ref={proxyRef.email} name='email' />
      <input ref={proxyRef.password} name='password' />
    </>
  );
};
```

## How it works

it will create a proxy that will return `{ current: defaultValue }` when you'll try to access a key from it, and it will store it in the proxy, so you can access the value later

---
_Source: https://npm.io/package/@mrii/react-proxy-ref · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
