Skip to content

Latest commit

 

History

History
35 lines (23 loc) · 621 Bytes

useEffectOnce.md

File metadata and controls

35 lines (23 loc) · 621 Bytes

useEffectOnce

A hook to run an effect only once on mount.

Arguments

  • callback (function): The effect function to run once.

Returns

  • None

Hooks Involved

How to Use

import { useState } from "react"
import useEffectOnce from "./useEffectOnce"

export default function EffectOnceComponent() {
    const [count, setCount] = useState(0)

    useEffectOnce(() => alert("Hi"))

    return (
        <>
            <div>{count}</div>
            <button onClick={() => setCount(c => c + 1)}>Increment</button>
        </>
    )
}