# uhooks-fx

> uhooks with propagated states

Latest version **0.4.0** (published 2022-05-23) · ISC license · 0 weekly downloads

## Install

```sh
npm install uhooks-fx
pnpm add uhooks-fx
yarn add uhooks-fx
bun add uhooks-fx
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2022-05-23 |
| First published | 2020-12-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 24.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Andrea Giammarchi |
| Maintainers | webreflection |
| Keywords | uhooks, helper, useState, useReducer, propagation, updates |

## Links

- npm: https://www.npmjs.com/package/uhooks-fx
- Repository: https://github.com/WebReflection/uhooks-fx
- Homepage: https://github.com/WebReflection/uhooks-fx#readme
- Issues: https://github.com/WebReflection/uhooks-fx/issues
- npm.io page: https://npm.io/package/uhooks-fx

## Dependencies (1)

- [uhooks](https://npm.io/package/uhooks.md) ^0.4.0

## Alternatives

- [lodash.assign](https://npm.io/package/lodash.assign.md) — 2.3M weekly downloads
- [lodash.chunk](https://npm.io/package/lodash.chunk.md) — 1.8M weekly downloads
- [react-native-ios-utilities](https://npm.io/package/react-native-ios-utilities.md) — 138.5K weekly downloads
- [@technically/lodash](https://npm.io/package/@technically/lodash.md) — 50.9K weekly downloads
- [@fluid-topics/ft-icon](https://npm.io/package/@fluid-topics/ft-icon.md) — 20.6K weekly downloads

## Recent versions

- 0.4.0 (latest) — 2022-05-23
- 0.3.0 — 2022-05-05
- 0.2.4 — 2021-02-20
- 0.2.3 — 2021-01-08
- 0.2.2 — 2021-01-06
- 0.2.1 — 2021-01-04
- 0.2.0 — 2020-12-29
- 0.1.7 — 2020-12-26
- 0.1.6 — 2020-12-24
- 0.1.5 — 2020-12-21
- 0.1.4 — 2020-12-20
- 0.1.3 — 2020-12-20
- 0.1.2 — 2020-12-20
- 0.1.1 — 2020-12-20
- 0.1.0 — 2020-12-20

## README

# <em>µ</em>hooks-fx

[![CSP strict](https://webreflection.github.io/csp/strict.svg)](https://webreflection.github.io/csp/#-csp-strict)

This module allows reduced/state updates to propagate to an outer hook, avoiding duplicated execution of inner hooks for libraries that have contained updates such as [<em>µ</em>land](https://github.com/WebReflection/uland#readme).

This module exports same utilities via `uhooks-fx/async`, which is based on `uhooks/async` for asynchronous hooks.

### Example
```js
const test = ({hooked, dropEffect, useEffect, useState}) => {

  const state = initial => {
    const result = useState(initial);
    useEffect(() => {
      console.log('\x1b[2m', initial, 'fx in', '\x1b[0m');
      return () => {
        console.log('\x1b[2m', initial, 'fx out', '\x1b[0m');
      };
    }, []);
    console.log('\x1b[2m', 'state value:', result[0], '\x1b[0m');
    return result;
  };

  const first = hooked(state);
  const second = hooked(state);

  const parent = hooked(
    () => {
      const [a, $a] = first('a');
      const [b, $b] = second('b');
      // with uhooks inner updates don't propagate
      // so this will be logged only once
      // with uhooks-fx though, inner changes schedule
      // an update for the outer hook, in this case
      // the parent callback, so this will be logged
      // twice, with updated values too
      console.log('', a, b);
      if (a === 'a')
        $a('$a');
      if (b === 'b')
        $b('$b');
    },
    // there is an extra argument to flag a hook as parent
    true
  );

  parent();

  setTimeout(dropEffect, 0, first);
  setTimeout(dropEffect, 0, second);
};

// verify the difference
setTimeout(test, 100, require('uhooks'));
setTimeout(test, 200, require('uhooks-fx'));
```

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