Skip to main content
Version: 5.6.0

useUpdateEffect

About​

An useEffect that does not run on first render

Installation​

npm install --save rooks

Importing the hook​

import { useUpdateEffect } from 'rooks';

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

Codesandbox Example​

Basic Usage​

Join Bhargav's discord server​

You can click on the floating discord icon at the bottom right of the screen and talk to us in our server.