Search code examples
javascripthtmlcsstypescriptsvelte

How to Re-render a component in +layout.svelte


How to re-render a component in +layout.svelte, whenever the userType changes?

I am expecting to switch a navbar state between login and logout, navbar state depends on currentUserType.i have a store for currenUsertype. i want to show login button when user is logedout and when user login into the account then button should disappear from the navbar dynamically.


Solution

  • You can use the +layout.svelte component like any other. That means you subscribe to the store by writing $ in front of it, and then you can just use if.

    {#if $currentUserType === "loggedIn"}
    

    And so on.