surface v0.1.0-alpha.1 Surface.Component behaviour View Source

Defines a stateless component.

Example

defmodule Button do
  use Surface.Component

  property click, :event

  def render(assigns) do
    ~H"""
    <button class="button" phx-click={{ @click }}>
      <slot/>
    </button>
    """
  end
end

Note: Stateless components cannot handle Phoenix LiveView events. If you need to handle them, please use a Surface.LiveComponent instead.

Link to this section Summary

Callbacks

This optional callback is invoked in order to set up a context that can be retrieved for any descendent component.

Link to this section Callbacks

Link to this callback

init_context(props)

View Source (optional)
init_context(props :: map()) :: {:ok, keyword()} | {:error, String.t()}

This optional callback is invoked in order to set up a context that can be retrieved for any descendent component.