IRenderer: {
    render: ((host, options?) => void);
    unrender?: ((host, options?) => void);
}

A type describing a custom element renderer

Type declaration

  • render: ((host, options?) => void)

    Customize how a DOM node is rendered. If .renderer is set on a given instance of VirtualElement, this function will be called every time that VirtualElement is rendered.

      • (host, options?): void
      • Parameters

        • host: HTMLElement

          The actual DOM node created for a VirtualElement during rendering.

          On render, host is created and its attrs are set/updated via the standard routines in updateContent. host is then handed off to this function.

          The render function is free to modify host. The only restriction is is that render should not modify any attributes set by external routines (ie updateContent), as this may cause thrashing when the virtual element is next rendered.

        • Optional options: {
              attrs?: ElementAttrs;
              children?: ReadonlyArray<VirtualNode>;
          }

          Will be populated with the .attrs and .children fields set on the VirtualElement being rendered.

        Returns void

  • Optional unrender?: ((host, options?) => void)

    Optional cleanup function for custom renderers. If the .renderer field of a VirtualELement is set, and if .renderer.unrender is defined, when the element is changed or removed its corresponding DOM element will be passed to this function immediately before it is removed from the DOM.

    unrender is not required for for simple renderers, such as those implemented using document.createElement(). However, for certain rendering techniques explicit cleanup is required in order to avoid resource leaks.

    For example, if render calls ReactDOM.render(..., host), then there has to also be a corresponding implementation of unrender that calls ReactDOM.unmountComponentAtNode(host) in order to prevent a memory leak.

      • (host, options?): void
      • Parameters

        • host: HTMLElement

          the DOM element to be removed.

        • Optional options: {
              attrs?: ElementAttrs;
              children?: ReadonlyArray<VirtualNode>;
          }

          Will be populated with the .attrs and .children fields set on the VirtualElement being unrendered.

        Returns void