React Hook Triggered Only Once On Mount – useMountEffect

useMountEffect is a React hook triggered only once on mount.

How to use it:

1. Install and import the useMountEffect hook.

# NPM
$ npm install use-mount-effect
import { useMountEffect } from "use-mount-effect";

2. Usages.

const MyComponent = () => {
  useMountEffect(() => {
    // Do something
  });
  return <div>Blah blah blah</div>;
};
// With cleanup
import { useMountEffect } from "use-mount-effect";
const MyComponent = () => {
  useMountEffect(() => {
    // Do something
    return () => {
      // Do something
    };
  });
  return <div>...</div>;
};

Download Details:

Author: unixzii

Live Demo: View The Demo

Download Link: Download The Source Code

Official Website: https://github.com/unixzii/use-mount-effect

License: MIT

Tags:

Add Comment