# @tourepedia/react-hooks

> Common utility react hooks

Latest version **0.5.5** (published 2020-08-22) · MIT license · 0 weekly downloads

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

## Install

```sh
npm install @tourepedia/react-hooks
pnpm add @tourepedia/react-hooks
yarn add @tourepedia/react-hooks
bun add @tourepedia/react-hooks
```

## Health

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

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.5.5 |
| Published | 2020-08-22 |
| First published | 2019-05-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 32.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Sudhir Mitharwal |
| Maintainers | sudkumar |

## Links

- npm: https://www.npmjs.com/package/@tourepedia/react-hooks
- Repository: https://github.com/sembark/gladio
- Homepage: https://github.com/sembark/gladio#readme
- Issues: https://github.com/sembark/gladio/issues
- npm.io page: https://npm.io/package/@tourepedia/react-hooks

## Dependencies (1)

- [@tourepedia/dom-helpers](https://npm.io/package/@tourepedia/dom-helpers.md) ^0.3.2

## Recent versions

- 0.5.5 (latest) — 2020-08-22
- 0.5.4 — 2019-11-06
- 0.5.3 — 2019-11-01
- 0.5.2 — 2019-10-09
- 0.5.1 — 2019-10-09
- 0.5.0 — 2019-10-06
- 0.4.1 — 2019-10-03
- 0.4.0 — 2019-09-28
- 0.3.2 — 2019-09-21
- 0.3.1 — 2019-06-08
- 0.3.0 — 2019-06-02
- 0.2.7 — 2019-06-01
- 0.2.6 — 2019-06-01
- 0.2.5 — 2019-05-31
- 0.2.4 — 2019-05-31
- … 3 more at https://npm.io/package/@tourepedia/react-hooks/versions

## README

# React Hooks

Some helper react hooks

## Install

```
npm install --save @tourepedia/react-hooks
```

## Usage

### useDidMount

Call a function on component's didMount Lifecycle

```js
import { useDidMount } from "@tourepedia/react-hooks"

function App() {
  useDidMount(() => {
    // only called on mount
    fetchTheData()
  })
}
```

### useDidUpdate

Call a function only in component's didUpdate Lifecycle.

```js
import { useDidUpdate } from "@tourepedia/react-hooks"

function App({ count }) {
  useDidUpdate(() => {
    // called when the count changes
  }, [count])
}
```

### useOnce

Only call a function once in a component's Lifecycle

```js
import { useOnce } from "@tourepedia/react-hooks"

function App() {
  useOnce(() => {
    // only called once
    fetchTheData()
  })
}
```

### useEnforceFocus

Enforces focus to be contained in a container and return back to last focused element based on a condition

```js
useEnforceFocus(
  containerRef, // React.Ref: of the container
  shouldBeFocused, // boolean: (true) to toggle the focus enforcement
  config: {
    autoFocus // boolean: (true) should the container be autoFocus
    enforceFocus // boolean: (true) should return the focus to the last focused element
  }
)
```

```js
import { useRef, useState } from "react"
import { useEnforceFocus } from "@tourepedia/react-hooks"

function App() {
  const containerRef = useRef()
  const [shouldBeFocused, toggleShouldFocus] = useState(false)
  // will focus the form container when shouldBeFocused is set to true
  useEnforceFocus(containerRef, shouldBeFocused)
  return (
    <div>
      <form className="container" ref={containerRef}>
        <input type="email" autoFocus />
        <button type="submit">Save</button>
      </form>
      <button onClick={() => toggleShouldFocus(!shouldBeFocused)}>
        Toggle Focus
      </button>
    </div>
  )
}
```

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