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

@ehynds/use-change-effect

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ehynds/use-change-effect

Run an effect when a value changes

  • 1.0.0
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

useChangeEffect

build status

Run an effect when a value changes. Useful when you want to:

  • Know when a prop, state, or other value changes.
  • Know what the previous value was.
  • Avoid running the effect on mount.

Installation

$ npm install --save @ehynds/use-change-effect

# or

$ yarn add @ehynds/use-change-effect

Usage

import { useChangeEffect } from '@ehynds/use-change-effect';

const Component = ({ loading }) => {
  useChangeEffect(
    (prevLoading) => {
      console.log(`loading changed from ${prevLoading} to ${loading}`);
    },
    [loading]
  );

  ...
}

If the dependencies array contains multiple values, each previous value is passed to the effect as separate arguments:

useChangeEffect(
  (prevLoading, prevError) => {
    console.log('loading and/or error changed', { prevLoading, prevError });
  },
  [loading, error]
);

Keywords

FAQs

Package last updated on 20 Feb 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