Home > Enterprise >  Is it guaranteed that Svelte's onMount() is called once in production?
Is it guaranteed that Svelte's onMount() is called once in production?

Time:10-11

Given that onMount() of Svelte is a example image

Does this only happen in REPL, or also in the production version?

CodePudding user response:

In the REPL everytime you modify the code the component is re-mounted because it has changed and should now show a different component.

In a production app this will not happen because you are not changing the code anymore. It will however be called once per instance of this component:

<Component />
<Component />
<Component />
<Component />

the above code would fire the onMount in Component 4 times because you have 4 instances of it.

  • Related