Skip to content

Instantly share code, notes, and snippets.

@armchair-traveller
Last active June 25, 2021 00:20
Show Gist options
  • Save armchair-traveller/f6b89a82acb841e80f7da63a38cf5b08 to your computer and use it in GitHub Desktop.
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
<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>
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