跳至主要内容

useFirstMountState

返回組件是否剛剛掛載的 React Hook

Usage

即時編輯器

function Demo() {
  const isFirstMount = useFirstMountState();
  const [render, reRender] = useState(0);

  return (
    <div>
      <span>這個組件剛剛掛載: {isFirstMount ? "是" : "否"}</span>
      <br />
      <button onClick={() => reRender(1)}>{render}</button>
    </div>
  );
};

結果
這個組件剛剛掛載: 是

API

useFirstMountState

Returns

boolean: 組件是否剛剛掛載的布爾值

Arguments

Squarespace
Squarespace makes your marketing, customer management, and checkout flow effortless—all on a single platform.
Get Started