Native (mobile)

Static mounting

Because component constructors, event handlers and effects may need to be reconstructed on the other thread, native miso threads them across the boundary as static pointers rather than closures. This requires the StaticPointers language extension.

The root component is mounted with mountStatic wrapped in static:

{-# LANGUAGE StaticPointers #-}
module Main where

import Miso
import Miso.Native

main :: IO ()
main = native nativeEvents (static (mountStatic app))

Child components are embedded in a view the same way, with vcomp:

view _ =
  view_ []
    [ vcomp_ (static (mountStatic child)) ]

VCompStatic

VCompStatic is the View constructor behind vcomp. Unlike VComp it carries a StaticPtr to its component constructor, giving the mount a stable, cross-thread-resolvable identity (a StaticKey) instead of relying on a manually-supplied Key. This is what lets the MTS independently reconstruct a mirror of a component mounted on the BTS, including ones mounted after the initial frame, and is also how actions dispatched from a main-thread handler get routed back to the correct component on the BTS.

The StaticKey itself serves as the mount's identity, so there is no need for (+>) or a manual key — use vcomp (or vcomp_ when the child takes no props) together with mountStatic to build a VCompStatic. mountStatic accepts components with props directly; for a context-reading child, mount comp { useContext = True }.