import React, { useEffect, useRef } from 'react'; const [counter, setCounter] = useState(0); const didMount = useRef(false); const doSomething = () => { setCounter(123); } useEffect(() => { // Return early, if this is the first render: if ( !didMount.current ) { return didMount.current = true; } // Paste code to be executed on subsequent renders: console.log('Do something after counter has changed', counter); }, [counter]);
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter