Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

React hook for checking if the component is mounted.

License

Notifications You must be signed in to change notification settings

fabiospampinato/react-use-mounted

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

React - useMounted

React hook for checking if the component is mounted.

Install

npm install --save react-use-mounted

Usage

import {useState} from 'react';
import useMounted from 'react-use-mounted';

function MyComponent () {

  const [foo, setFoo] = useState ( false );
  const mounted = useMounted ();

  useWhatever ( () => {
    if ( !mounted.current ) return; // Not mounted, avoiding calling `setFoo`
    setFoo ( true );
  });

}

License

MIT © Fabio Spampinato

About

React hook for checking if the component is mounted.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published