@ithreat/use-mounted
v1.1.0
Published
useMounted hook for checking to see whether a component is mounted
Downloads
3
Keywords
Readme
@ithreat/use-mounted
useMounted hook for checking to see whether a component is mounted
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.