# @over-ui/use-controlled

> `useControlled` 패키지는, `over-ui` 에서 상태를 관리하는 훅입니다. 내부에서만 사용하는 패키지입니다.

Latest version **1.1.0** (published 2023-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install @over-ui/use-controlled
pnpm add @over-ui/use-controlled
yarn add @over-ui/use-controlled
bun add @over-ui/use-controlled
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2023-01-03 |
| First published | 2023-01-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 22.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Maintainers | lv0314, otterp012 |

## Links

- npm: https://www.npmjs.com/package/@over-ui/use-controlled
- Repository: https://github.com/over-ui/unstyled
- Homepage: https://github.com/over-ui/unstyled/tree/main#readme
- Issues: https://github.com/over-ui/unstyled/issues
- npm.io page: https://npm.io/package/@over-ui/use-controlled

## Recent versions

- 1.1.0 (latest) — 2023-01-03

## README

# `over-ui/useControlled`

`useControlled` 패키지는, `over-ui` 에서 상태를 관리하는 훅입니다.
내부에서만 사용하는 패키지입니다.

## Usage

```jsx
const Toggle: Poly.Component<typeof DEFAULT_TOGGLE, ToggleProps> =
  React.forwardRef(
    <T extends React.ElementType = typeof DEFAULT_TOGGLE>(
      props: Poly.Props<T, ToggleProps>,
      ref: Poly.Ref<T>,
    ) => {
      const {
        onClick,
        onKeyDown,
        onPressedChange,
        disabled = false,
        children,
        defaultPressed = false,
        pressed: pressedProp,
        as,
        ...restProps
      } = props;

      const [pressed, setPressed] = useControlled({
        value: pressedProp,
        defaultValue: defaultPressed,
        onChange: onPressedChange,
      });

      ...
      );
    },
  );

```

이를 통해, 다음과 같이 이용할 수 있습니다.

```jsx
function Home() {
  const [state, setState] = useState(false);
  return (
    <>
      <Toggle pressed={state} onPressedChange={(pressed) => setState(pressed)} />
    </>
  );
}
```

- useControlled의 value, onValueChange를 이용할 경우 외부의 상태를 이용할 수 있습니다.

```jsx
function Home() {
  return (
    <>
      <Toggle
        defaultPressed={false}
        onPressedChange={(pressed) => console.log(pressed)}
        // false
      />
    </>
  );
}
```

- 외부의 상태를 정의하지 않고, 내부의 상태만을 활용할 수 있습니다.

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