react-code-dataset / react-use /docs /useFirstMountState.md
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
|
raw
history blame
589 Bytes

useFirstMountState

Returns true if component is just mounted (on first render) and false otherwise.

Usage

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

const isFirstMount: boolean = useFirstMountState();