live_props v0.2.2 LiveProps.Props View Source

Functions for working with props. This wil be made available whenever you use LiveProps.LiveComponent within a Phoenix.LiveComponent.

Link to this section Summary

Functions

Define a property with the given name and type. Returns :ok

Link to this section Functions

Link to this macro

prop(name, type, opts \\ [])

View Source (macro)

Specs

prop(name :: atom(), type :: atom(), opts :: list()) :: :ok

Define a property with the given name and type. Returns :ok

This macro is meant to be called within a LiveComponent only. Types can be any atom and are just for documentation purposes.

Options:

  • :default - A default value to assign to the prop.
  • :required - boolean. If true, an error will be raised if the prop is not passed to the component.
  • :compute - 1-arity function that takes the socket assigns as an argument and returns the value to be assigned. Can be an atom of the name of a function in your component or a remote function call like &MyModule.compute/1. If you use an atom, the referenced function must be public.
  • :doc - String. Will be added to module documentation.