side effect functions working in react and svelte

Viewed 21

as all know we put a dependency array in useEffect. But when we use the onMount method in svelte which is equivalent to useEffect, it doesn't require dependency array. Can anyone explain me why.

 //// React  ////

useEffect( ()=>{
         // side effects goes here //
},[])  


//// Svelte  ////

onMount(  ()=>{
        // side effects goes here  //
})
1 Answers

onMount is used when the component is rendered. However, in react, useEffect receives an array of dependencies and if one of these dependencies is updated, that will cause the component to re-render. Hope that answers your question!

Related