Skip to content

Latest commit

 

History

History
29 lines (22 loc) · 589 Bytes

useFirstMountState.md

File metadata and controls

29 lines (22 loc) · 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();