# Static mounting

> Component constructors cross the thread boundary as static pointers: mountStatic, vcomp and VCompStatic.

Source: https://haskell-miso.org/docs/native/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`:

```haskell
{-# 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`:

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

> **Careful:** **Static-pointer limitation.**A `static` form may only close over *top-level, closed* bindings — it cannot capture local variables. This is why component constructors and main-thread handlers are supplied as references to top-level definitions, with any runtime data (props, decoded event payloads) shipped separately as serialised values rather than captured in a closure.

## 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 }`.

> **Note:** Under `NATIVE`, `(+>)`, `mount_` and `mountWithProps_` build a `VComp` with no `StaticKey`. A component mounted that way as part of the *initial* frame is fine, but if it is mounted *later* — inside a list or behind a conditional — the MTS never registers a mirror for it, and any main-thread handler inside that subtree silently fails to dispatch. Use `vcomp` with `mountStatic` for anything that may mount after the first frame.
