Add scoped function

Add a function to handle the common enter-leave pattern.
typo, I'll update