useFirstRender

This Hook is available since v1.5.0.

A React Hook for determining whether the component is currently in its initial render.

Demo

Source

Open the console to see the log. (Rspress will render twice when demo mounted)

isFirstRender:
true
Count:
0

Usage

const isFirstRender = useFirstRender() // when component first renders console.log(isFirstRender) // true // when component re-renders console.log(isFirstRender) // false

Source

Click links below to view source on GitHub.

API

const isFirstRender = useFirstRender()

Returns

A boolean value indicating whether the component is currently in its first render phase.