component-lifespan
v1.0.1
Published
`ComponentLifespan` is a React Component that measures it's own lifespan, and subsequently the lifespan of it's children. It is a simple-to-use component to help time certain things.
Downloads
3
Readme
useStateList
ComponentLifespan
is a React Component that measures it's own lifespan, and subsequently the lifespan of it's children. It is a simple-to-use component to help time certain things.
Install
npm install component-lifespan
oryarn add component-lifespan
Use
import React, { useState } from 'react';
import ComponentLifespan from 'component-lifespan';
const MyDummyComponent = () => {
const [show, setShow] = useState(true);
const [lifetime, setLifetime] = useState();
const handleClick = () => setShow(false);
return (
<>
<h1>Component Lifespan Test</h1>
{show && (
<ComponentLifespan updateElapsedTime={setLifetime}>
<button type="button" onClick={handleClick}>
Click Me!
</button>
</ComponentLifespan>
)}
{lifetime && <h2>Comonent lasted {lifetime / 1000} seconds</h2>}
</>
);
};