跳到主要内容

useUpdate

强制更新函数

Usage

实时编辑器

function Demo() {
  const update = useUpdate();

  return (
    <>
      {/* to avoid ssr error beacause date.now() will not be same in server and client */}
      <div suppressHydrationWarning={true}>Time: {Date.now()}</div>
      <button onClick={update}>Update</button>
    </>
  );
};

结果
Time: 1760435401618

API

useUpdate

Returns

() => void: 强制更新函数

Arguments

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