Created
December 11, 2018 09:42
-
-
Save ThaddeusJiang/9deecdce10661f5b2fffb708f6aeb0c0 to your computer and use it in GitHub Desktop.
reset state when change the entity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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