@rodw95/use-mounted-state
TypeScript icon, indicating that this package has built-in type declarations

0.0.1 • Public • Published

use-mounted-state

React hook to check mounted state

Install

yarn add @rodw95/use-mounted-state

// or

npm install @rodw95/use-mounted-state

Example

import useIsMounted from '@rodw95/use-mounted-state';
import React, { useCallback, useState } from 'react';

export default () => {
	const isMounted = useIsMounted();
	const [state, setState] = useState(null);

	 const doFetch = useCallback(async () => {
		 const result = await fetchAsync();
		 if (isMounted()) {
			 // Only set state if still mounted
			 setState(result);
		 }
	 });

	 return (
		 // ...
	 );
};

License

MIT

Readme

Keywords

Package Sidebar

Install

npm i @rodw95/use-mounted-state

Weekly Downloads

50

Version

0.0.1

License

MIT

Unpacked Size

3.63 kB

Total Files

5

Last publish

Collaborators

  • robbieopdeweegh