title: Mithril: render component on event/dynamically
body: <p>Trying to get the hang of Mithril, can't really understand one thing. Can I render components on events?</p>
  
  <p>Let's assume I have one parent component:</p>
  
  <pre><code>var MyApp = {
      view: function() {
          return m("div", [
              m.component(MyApp.header, {}),
              m("div", {id: "menu-container"})
          ])
      }
  
  };
  
  m.mount(document.body, megogo.main);
  </code></pre>
  
  <p>It renders the header component (and a placeholder for the menu (do I even need it?)):</p>
  
  <pre><code>MyApp.header = {
      view: function() {
          return m("div", {
              id: 'app-header'
          }, [
              m('a', {
                  href: '#',
                  id: 'menu-button',
                  onclick: function(){
                      // this part is just for reference
                      m.component(MyApp.menu, {})
                  }
              }, 'Menu')
          ])
      }
  }
  </code></pre>
  
  <p>When the user clicks on the menu link I want to load the menu items from my API and only then render the menu.</p>
  
  <pre><code>MyApp.menu = {
      controller: function() {
          var categories = m.request({method: "GET", url: "https://api.site.com/?params"});
          return {categories: categories};
      },
      view: function(ctrl) {
          return m("div", ctrl.categories().data.items.map(function(item) {
              return m("a", {
                  href: "#",
                  class: 'link-button',
                  onkeydown: MyApp.menu.keydown
              }, item.title)
          }));
      },
      keydown: function(e){
          e.preventDefault();
          var code = e.keyCode || e.which;
          switch(code){
              // ...
          }
      }
  };
  </code></pre>
  
  <p>This part will obviously not work</p>
  
  <pre><code>onclick: function(){
      // this part is just for reference
      m.component(MyApp.menu, {})
  }
  </code></pre>
  
  <p>So, the question is what is the correct way render components on event?</p>