Skip to content

Instantly share code, notes, and snippets.

@deviationist
Last active June 27, 2023 15:31
Show Gist options
  • Save deviationist/1788444263d77159fba0e9415ef6aacc to your computer and use it in GitHub Desktop.
Save deviationist/1788444263d77159fba0e9415ef6aacc to your computer and use it in GitHub Desktop.
React's useEffect, but it does not run on initial render.
import React from 'react';
export function useEffectNonInit(effect: Function, deps: React.DependencyList) {
const isInitial = React.useRef(true);
React.useEffect(() => {
if (isInitial.current) {
isInitial.current = false;
return;
}
effect();
}, deps);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment