Last active
June 25, 2021 00:20
-
-
Save armchair-traveller/f6b89a82acb841e80f7da63a38cf5b08 to your computer and use it in GitHub Desktop.
[Svelte] onMount doesn't have to be defined/called specifically in the component
This file contains 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
<script> | |
import mountIt from './mountIt'; | |
mountIt(); // logs when the component is mounted. Must be called in the component's script tag, during initialization. | |
// if you want to get a value out of the onMount, you could use promises, reactive declarations, stores, etc. | |
</script> |
This file contains 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
import { onMount } from './onMount'; | |
function mountIt() { | |
onMount(() => { | |
console.log('the component has mounted'); | |
}); | |
} | |
export default mountIt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment