Nostalgic Perogi Monogramming
    Wondering what’s next for npm?Check out our public roadmap! »

    react-use-trig

    0.1.1 • Public • Published

    🧹 react-use-trig

    A React Hook that manages and cleans up after calls to setTimeout()

    It triggers functions and keeps them from leaking all over the floor. When using trig(), every time a component is cleaned up by React, it's pending Timeouts are cleared.

    Install

    npm install react-use-trig

    Usage

    Learn how to use it in 6 seconds:

    import useTrig from 'react-use-trig';
    
    function Example(): JSX.Element {
      const { trig } = useTrig();
    
      trig(setTimeout(() => console.log('pass a NodeJS.Timeout returned from setTimeout()'), 1000));
    
      trig([
        setTimeout(() => console.log('pass an array of NodeJS.Timeouts'), 2000),
        setTimeout(() => console.log('pass an array of NodeJS.Timeouts'), 3000),
      ]);
    
      trig({ t: 4000, f: () => console.log('pass TimeoutArgs with milliseconds t and function f') });
      
      trig([
        { t: 5000, f: () => console.log('pass an array of TimeoutArgs') },
        { t: 6000, f: () => console.log('pass an array of TimeoutArgs') },
      ]);
    
      return <></>;
    }

    trig : adjective (comparative trigger, superlative triggest)

    • True; trusty; trustworthy; faithful.
    • Safe; secure.
    • Tight; firm; steady; sound; in good condition or health.
    • Neat; tidy; trim; spruce; smart.

    Install

    npm i react-use-trig

    DownloadsWeekly Downloads

    4

    Version

    0.1.1

    License

    MIT

    Unpacked Size

    5.56 kB

    Total Files

    8

    Last publish

    Collaborators

    • avatar