Package Exports
- @rooks/use-update-effect
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@rooks/use-update-effect) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
@rooks/use-update-effect
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 />);