Version 2.x : How to force a rerender on a component?

We’ve been trying to rerender a component on one of our routes. Our current solution is a bit messy.

{#if toggle}} {{component}} {{else}} {{component}} {{/if}}

We are basically changing the toggle to destroy the current component and spawn the same component again. Is there a cleaner way of doing this?

Why is the component dependent on a re-render? This seems highly inefficient (and a performance hit). Is it possible to have the component capable of correctly reacting to changes in the environment instead of needing a re-render?

If this is something like you need to instruct the component to re-fetch some data then it might be better to consider moving that logic into a service that way the component can react to the services changes while others can send messages to the service instructing it to update.

Another option is to provide a manager to the parent so the parent has a method to call that will instruct the component to do the right thing. I explain this pattern in great detail here: A possible actions down pattern

2 Likes