Skip to content
On this page

useFirstMountState

检查当前的组件是否为第一次渲染的 Hook。

Demo

Only first render wil be show
state: 0
<template>
<div v-if="isFirst">Only first render wil be show</div>
<div>state: {{ state }}</div>
<button @click="setState(c => c + 1)">update</button>
</template>

<script lang="ts" setup>
import { useState, useFirstMountState } from 'v3-use'

const [state, setState] = useState(0)
const isFirst = useFirstMountState()
</script>

Usage

import { useFirstMountState } from 'v3-use'
const isFirst = useFirstMountState()
import { useFirstMountState } from 'v3-use'
const isFirst = useFirstMountState()

Reference

Type Declarations

export declare function useFirstMountState(): Ref<boolean>
export declare function useFirstMountState(): Ref<boolean>