Create a hook to tell if it is the first render.
useRef 所返回的对象在组件的生命周期中持续存在,能够用来判断是否为第一次渲染,useRef 会在每次渲染时返回同一个 ref 对象
import {useRef} from 'react'export function useIsFirstRender() {// your code hereconst ref = useRef(0)ref.current++;return ref.current === 1;}
