Discord
Source code

use-did-update

Call function in useEffect when value changes, but not when component mounts
Import

Usage

When component mounts useEffect hook is called. This is fine in most cases but if you need to track value changes and not component mount you will need to implement something like this to prevent useEffect call on mount:

const mounted = useRef(false);
useEffect(() => {
if (mounted.current) {
fn();
} else {
mounted.current = true;
}
}, dependencies);

use-did-update uses the same logic:

useDidUpdate(() => console.log("Won't be called when mounted"), [value]);

Definition

function useDidUpdate(fn: () => void, dependencies?: any[]): void;
Build fully functional accessible web applications with ease
Feedback
Your feedback is most valuable contribution to the project, please share how you use Mantine, what features are missing and what is done good
Leave feedback