Skip to content

Instantly share code, notes, and snippets.

View Alfxjx's full-sized avatar
🐶

Xu Jianxiang Alfxjx

🐶
View GitHub Profile
@jsun969
jsun969 / useMount.ts
Created November 2, 2023 20:26
use f**king mount
import { useEffect, useRef } from 'react'
export const useMount = (fn: React.EffectCallback) => {
const isMounted = useRef(false)
useEffect(() => {
if (!isMounted.current) {
fn()
isMounted.current = true
}
}, [])