Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

uhooks-fx

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

uhooks-fx

uhooks with propagated states

  • 0.2.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
18
decreased by-66.04%
Maintainers
1
Weekly downloads
 
Created
Source

µhooks-fx

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 µland.

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

Example

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'));

Keywords

FAQs

Package last updated on 04 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc