react useeffect prevent first time

Solutions on MaxInterview for react useeffect prevent first time by the best coders in the world

showing results for - "react useeffect prevent first time"
Elias
10 Jun 2016
1import { useRef, useEffect } from 'react';
2
3export function useFirstRender() {
4  const firstRender = useRef(true);
5
6  useEffect(() => {
7    firstRender.current = false;
8  }, []);
9
10  return firstRender.current;
11}
Alannah
22 May 2020
1import { useRef, useEffect } from 'react';
2
3export function useFirstRender() {
4  const firstRender = useRef(true);
5
6  useEffect(() => {
7    firstRender.current = false;
8  }, []);
9
10  return firstRender.current;
11}
12