# @elemental-ui-alpha/utils

> The utils package provides a grab-bag of utility hooks and helpers for React development.

Latest version **0.0.2** (published 2020-04-24) · 0 weekly downloads

## Install

```sh
npm install @elemental-ui-alpha/utils
pnpm add @elemental-ui-alpha/utils
yarn add @elemental-ui-alpha/utils
bun add @elemental-ui-alpha/utils
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; low quality score; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2020-04-24 |
| First published | 2020-04-23 |
| Weekly downloads | 0 |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 6 |
| Unpacked size | 10 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | dsf-release-bot, mitchellhamilton |

## Links

- npm: https://www.npmjs.com/package/@elemental-ui-alpha/utils
- npm.io page: https://npm.io/package/@elemental-ui-alpha/utils

## Dependencies (6)

- [facepaint](https://npm.io/package/facepaint.md) ^1.2.1
- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.8.3
- [@reach/auto-id](https://npm.io/package/@reach/auto-id.md) ^0.7.2
- [@elemental-ui/utils](https://npm.io/package/@elemental-ui/utils.md) ^0.1.0
- [@elemental-ui-alpha/core](https://npm.io/package/@elemental-ui-alpha/core.md) ^0.0.2
- [@elemental-ui-alpha/theme](https://npm.io/package/@elemental-ui-alpha/theme.md) ^0.0.0

## Recent versions

- 0.0.2 (latest) — 2020-04-24
- 0.0.1 — 2020-04-23
- 0.0.0 — 2020-04-23

## README

# Utils

```jsx
import {
  forwardRefWithAs,
  makeId,
  useClickOutside,
  useId,
  useKeyPress,
  useMediaQuery,
} from '@elemental-ui-alpha/utils';
```

## Use ID

Create unique IDs in your components.

```jsx
const id = useId();
return id; // "1"
```

You can optionally pass in a consumer fallback.

```jsx
const id = useId('my-component-id');
return id; // "my-component-id"
```

Use `makeId` to add a prefix.

```jsx
const id = makeId('my-prefix', '4');
return id; // "my-prefix--4"
```

## Forward Ref

`React.forwardRef` is re-exported from `@elemental-ui-alpha/utils` as `forwardRefWithAs` with different type
definitions to work with components that have an `as` prop. It accepts two type
arguments, `DefaultElementType` and `Props`.

```tsx
import { forwardRefWithAs } from '@elemental-ui-alpha/utils';

type Props = {
  color: string;
};

let Button = forwardRefWithAs<'button', Props>(
  ({ color, as: Tag = 'button', ...props }, ref) => {
    return <Tag css={{ color }} ref={ref} {...props} />;
  }
);
```

---
_Source: https://npm.io/package/@elemental-ui-alpha/utils · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
