Skip to content

Instantly share code, notes, and snippets.

@ThaddeusJiang
Created December 11, 2018 09:42
Show Gist options
  • Save ThaddeusJiang/9deecdce10661f5b2fffb708f6aeb0c0 to your computer and use it in GitHub Desktop.
Save ThaddeusJiang/9deecdce10661f5b2fffb708f6aeb0c0 to your computer and use it in GitHub Desktop.
reset state when change the entity
function usePrevious(value) {
const ref = React.useRef();
React.useEffect(() => {
ref.current = value;
});
return ref.current;
}
const prevEntity = usePrevious(entityType);
React.useEffect(() => {
// reset state when change the entity
if (prevEntity && prevEntity !== entityType) {
setSearchText('');
setIsActive(true);
setIsArchive(true);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment