# react-editable-hooks

> Hooks for managing editable field state

Latest version **1.0.0** (published 2019-04-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install react-editable-hooks
pnpm add react-editable-hooks
yarn add react-editable-hooks
bun add react-editable-hooks
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2019-04-21 |
| First published | 2019-04-21 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8 |
| Dependencies | 0 |
| Unpacked size | 17.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | cameronfletcher92 |
| Maintainers | cfletcheratlassian |

## Links

- npm: https://www.npmjs.com/package/react-editable-hooks
- Repository: https://github.com/cameronfletcher92/react-editable-hooks
- Homepage: https://github.com/cameronfletcher92/react-editable-hooks#readme
- Issues: https://github.com/cameronfletcher92/react-editable-hooks/issues
- npm.io page: https://npm.io/package/react-editable-hooks

## Recent versions

- 1.0.0 (latest) — 2019-04-21

## README

# react-editable-hooks

> Hooks for managing editable field state

[![NPM](https://img.shields.io/npm/v/react-editable-hooks.svg)](https://www.npmjs.com/package/react-editable-hooks) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)

## Install

```bash
npm install --save react-editable-hooks
```

## Usage

```tsx
import * as React from "react";
import { useEditableState } from "react-editable-hooks";

const EditableTextField = ({ value, onValueChanged }) => {
  const {
    onEditBegin,
    onEditConfirm,
    onEditCancel,
    isEditing,
    editValue,
    setEditValue,
    useDraft,
    hasDraft
  } = useEditableState({
    value,
    onValueChanged,
    localStorageKey: "ui.drafts.my-test-field"
  });

  if (isEditing) {
    return (
      <>
        <input
          className="content"
          value={editValue}
          onChange={e => setEditValue(e.target.value)}
        />
        <button onClick={onEditConfirm}>Confirm</button>
        <button onClick={onEditCancel}>Cancel</button>
      </>
    );
  } else {
    return (
      <>
        <span>{value}</span>
        <button onClick={onEditBegin}>Edit</button>
        {hasDraft ? <button onClick={useDraft}>Load draft</button> : null}
      </>
    );
  }
};
```

## License

MIT © [cameronfletcher92](https://github.com/cameronfletcher92)

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