@rooks/use-update-effect
TypeScript icon, indicating that this package has built-in type declarations

4.11.2 • Public • Published

@rooks/use-update-effect

Note: Future updates to this package have moved to the main package rooks. All hooks now reside in a single package which you can install using

npm install rooks

or

yarn add rooks

Rooks is completely treeshakeable and if you use only 1 of the 50+ hooks in the package, only that hook will be bundled with your code. Your bundle will only contain the hooks that you need. Cheers!

TitleCard

Build Status

About

An useEffect that does not run on first render

Installation

npm install --save @rooks/use-update-effect

Importing the hook

import useUpdateEffect from "@rooks/use-update-effect";

Usage

function Demo() {
  const [userID, setUserID] = useState();
  const [hasUpdated, setHasUpdated] = useState({ userID, updated: false });
  useUpdateEffect(() => {
    API.subscribe(userID);
    setHasUpdated({ userID, updated: true });
    () => {
      API.unsubscribe(userID);
      setHasUpdated({ userID, updated: false });
    };
  }, [value]);
  return (
    <>
      <button onClick={() => setUserID(Math.random())}>user ID is {userID}</button>
      <p>Has updated for userID - {hasUpdated.toString()}</p>
    </>
  );
}

render(<Demo />);

Package Sidebar

Install

npm i @rooks/use-update-effect

Weekly Downloads

50

Version

4.11.2

License

MIT

Unpacked Size

8.59 kB

Total Files

13

Last publish

Collaborators

  • imbhargav5