Skip to content

Instantly share code, notes, and snippets.

View chsilva's full-sized avatar
🏋️‍♀️
Focusing

caio chsilva

🏋️‍♀️
Focusing
  • Limeira/SP - Brazil
  • 13:38 (UTC -03:00)
View GitHub Profile
@chsilva
chsilva / useDidUpdateEffect.ts
Created June 10, 2021 13:21
this is a custom hook that works like a `didUpdate` lifecycle method in react with typescript
import { useEffect, useRef } from 'react'
function useDidUpdateEffect(fn: () => void, dependencies: any[]): void {
const mountRef = useRef<boolean>(false)
useEffect((): void => {
if (mountRef.current) {
fn()
} else {
mountRef.current = true