An open API service indexing awesome lists of open source software.

https://github.com/kunukn/use-mount

React onMount and onUnMount hook
https://github.com/kunukn/use-mount

Last synced: about 2 months ago
JSON representation

React onMount and onUnMount hook

Awesome Lists containing this project

README

        

# use-mount

## About

ReactJS Mount and UnMount callback hook.

```jsx
let ref = useMount({ onMount, onUnmount });
/*
onMount is an optional callback function,
onUnmount is an optional callback function.
The ref is attached to the component where the callbacks should apply.
*/
```

## Usage example

```jsx
import useMount from '@kunukn/use-mount';

let MyComponent = ({ children }) => {
let onMount = node => console.log('I mounted this node in the DOM:', node);
let onUnmount = node => console.log('I unmounted this node from the DOM:', node);
let ref = useMount({ onMount, onUnmount });
return

{children}
;
};

let App = () => {
let [isActive, setToggle] = React.useState(false);

return (


setToggle(s => !s)}>toggle
{isActive && This is my component}

);
};
```

## Demo

https://codesandbox.io/s/gifted-murdock-m3rzk