useFirstMountState
返回组件是否刚刚挂载的 React Hook
Usage
实时编辑器
function Demo() { const isFirstMount = useFirstMountState(); const [render, reRender] = useState(0); return ( <div> <span>This component is just mounted: {isFirstMount ? "YES" : "NO"}</span> <br /> <button onClick={() => reRender(1)}>{render}</button> </div> ); };
结果
Loading...
API
useFirstMountState
Returns
boolean