mirror of
https://github.com/streamich/react-use.git
synced 2025-12-08 18:02:14 +00:00
feat(useFirstMountState): hook to track if render is first; feat(useRendersCount): hook to track renders count; refactor(useUpdateEffect): now uses useFirstMountState hook; refactor(usePreviousDistinct): now uses with useFirstMountState hook; docs: update readme;
30 lines
589 B
Markdown
30 lines
589 B
Markdown
# `useFirstMountState`
|
|
|
|
Returns `true` if component is just mounted (on first render) and `false` otherwise.
|
|
|
|
## Usage
|
|
|
|
```typescript jsx
|
|
import * as React from 'react';
|
|
import { useFirstMountState } from 'react-use';
|
|
|
|
const Demo = () => {
|
|
const isFirstMount = useFirstMountState();
|
|
const update = useUpdate();
|
|
|
|
return (
|
|
<div>
|
|
<span>This component is just mounted: {isFirstMount ? 'YES' : 'NO'}</span>
|
|
<br />
|
|
<button onClick={update}>re-render</button>
|
|
</div>
|
|
);
|
|
};
|
|
```
|
|
|
|
## Reference
|
|
|
|
```typescript
|
|
const isFirstMount: boolean = useFirstMountState();
|
|
```
|