useOnce

React hook for running a function only once.

Installation

npm install @mvdlei/hooks

Example

0 Will only update once

Usage

import React from "react";
import { useOnce } from "@mvdlei/hooks";
 
const App = () => {
  const [count, setCount] = React.useState(0);
 
  useOnce(() => {
    console.log("Hello World!");
  });
 
  return (
    <div>
      <h1>Count: {count}</h1>
    </div>
  );
};

Reference

useOnce(callback: () => void): void;

use-once.ts