title: How to animate state transitions in Blazor?
body: <p>In my Blazor components I often render components based on either a conditional statement, e.g. </p>
  
  <pre><code>@if (_contact.IsCustomer)
  {
      &lt;SalesOrdersList Customer="@_contact" /&gt;
  }
  </code></pre>
  
  <p>Or from a loop, e.g.</p>
  
  <pre><code>@foreach(var salesOrder in _customer.SalesOrders)
  {
      &lt;SalesOrderSummary SalesOrder="@salesOrder" /&gt;
  }
  </code></pre>
  
  <p>When I change the state I'd like to animate the state transition so that the components fade in/out.  In the examples above that might happen when <code>IsCustomer</code> changes, or when a record is added or removed from the <code>SalesOrders</code> collection.  </p>
  
  <h3>Animating adding a component</h3>
  
  <p>I can see how this can be achieved when adding a component, by the component having a CSS class that has a fade in animation that occurs when the component renders - e.g. as shown in <a href="https://chrissainty.com/blazor-toast-notifications-using-only-csharp-html-css/" rel="noreferrer">Chris Sainty's excellent toast example</a></p>
  
  <h3>Animating removing a component</h3>
  
  <p>I can't think how you would do that when removing a component, because the component simply stops existing when that part of the DOM re-renders?</p>
  
  <p>React has <a href="https://github.com/reactjs/react-transition-group" rel="noreferrer">react-transition-group</a> that deals with the period of transition, but I can't find anything similar in Blazor as of yet?</p>
  
  <p>Is there any way to do add an animation for the removal of a component in Blazor?  </p>
  
  <h3>Animating Page Transitions</h3>
  
  <p>The other often-animated state-transition is changing 'pages'.  Again, I can't find way to do that in Blazor at present?  Effectively that can just be an animation for removing the old page component and another for adding the new one, but in some frameworks that's done at the routing level rather than the component level - I can't find anything at either level in Blazor at present?</p>