4.11.2 • Published 3 years ago

@rooks/use-update-effect v4.11.2

Weekly downloads
52
License
MIT
Repository
github
Last release
3 years ago

@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 Statusnpm.io npm.io npm.io npm.io

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 />);
4.11.1

3 years ago

4.11.2

3 years ago

4.11.0

3 years ago

4.10.1

3 years ago

4.10.0

3 years ago

4.9.2

3 years ago

4.9.1

3 years ago

4.9.0

3 years ago

4.9.0-canary.0

3 years ago

4.8.1

3 years ago

4.8.0

3 years ago

4.7.0

3 years ago

4.7.1

3 years ago

4.6.1

3 years ago

4.6.0

3 years ago