Skip to content

japhy-/use-mounted

Repository files navigation

@ithreat/use-mounted

useMounted hook for checking to see whether a component is mounted

NPM JavaScript Style Guide

Install

npm install --save @ithreat/use-mounted

Usage

import React, { useState } from 'react'

import { useMounted } from '@ithreat/use-mounted'

const Example = () => {
  const isMounted = useMounted()
  const [ value, setValue ] = useState()

  const func = (promise) => {
    promise.then((res) => {
      // if component is no longer mounted, stop now
      if (! isMounted()) return;

      // if component is mounted, we can update state
      setValue(res);
    })
  };
}

License

MIT © japhy-


This hook is created using create-react-hook.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published