New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

react-use-lifecycle-helpers

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-use-lifecycle-helpers

Helpers functions arround useEffect hook to make your life easier, providing the most use cases of useEffect hook, among them the lifecycle of class component.

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

react-use-lifecycle-helpers

Helpers functions arround useEffect hook to make your life easier, providing the most use cases of useEffect hook, among them the lifecycle of class component.

NPM JavaScript Style Guide

Install

npm install --save react-use-lifecycle-helpers

See Example

Usage

useDidMount

This hook is a replacement for the componentDidMount method.

import useLifecycleMethods from "react-use-lifecycle-helpers";

export default function MyComponent() {
  const { useDidMount } = useLifecycleMethods();

  useDidMount(() => {
    console.log("MyComponent is mounted");
  });
}

useDidUpdate

This hook is similar to the componentDidUpdate method.

import useLifecycleMethods from "react-use-lifecycle-helpers";

export default function MyComponent(props) {
  const [state, setState] = useState({ count: 0, bool: false });

  const { useDidUpdate } = useLifecycleMethods(state, props);

  useDidUpdate(() => {
    console.log("MyComponent is updated");
  });
}

useWillUnmount

A hook that's a replacement for the componentWillUnmount method.

import useLifecycleMethods from "react-use-lifecycle-helpers";

export default function MyComponent() {
  const { useWillUnmount } = useLifecycleMethods();

  useWillUnmount(() => {
    console.log("MyComponent will unmount");
  });
}

useDepsDidChange

Track multiple or one of the state properties.

import useLifecycleMethods from "react-use-lifecycle-helpers";

export default function MyComponent(props) {
  const [state, setState] = useState({ count: 0, bool: false });

  const { useDepsDidChange } = useLifecycleMethods(state, props);

  useDepsDidChange(
    prevState => {
      console.log("useDepsDidChange Count", state.count, prevState.count);
    },
    ["count"]
  );

  useDepsDidChange(
    prevState => {
      console.log("useDepsDidChange Bool", state.bool, prevState.bool);
    },
    ["bool"]
  );

  useDepsDidChange(
    prevState => {
      console.log("useDepsDidChange Count", state.count, prevState.count);
      console.log("useDepsDidChange Bool", state.bool, prevState.bool);
    },
    ["bool", "count"]
  );
}

License

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

Contributors

Todo

  • Migrate to TypeScript

Keywords

hook

FAQs

Package last updated on 16 Feb 2020

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