@utilityjs/use-previous-value
    TypeScript icon, indicating that this package has built-in type declarations

    1.0.1 • Public • Published

    usePreviousValue

    A React hook that returns a value from the previous render.

    license npm latest package npm downloads types

    npm i @utilityjs/use-previous-value | yarn add @utilityjs/use-previous-value

    Usage

    import usePreviousValue from "@utilityjs/use-previous-value";
    import * as React from "react";
    
    const useHook = () => {
      const [open, setOpen] = React.useState(false);
    
      const prevOpen = usePreviousValue(open);
    
      React.useEffect(() => {
        if (open !== prevOpen) {
          console.log("The state has been changed!");
        }
      }, [open])
    };

    API

    usePreviousValue(value)

    declare const usePreviousValue: <T>(value: T) => T | undefined;

    value

    The value on the current render.

    Install

    npm i @utilityjs/use-previous-value

    DownloadsWeekly Downloads

    8

    Version

    1.0.1

    License

    MIT

    Unpacked Size

    4.24 kB

    Total Files

    8

    Last publish

    Collaborators

    • mimshins