Set initial value of data from a prop if it was set

Hello, I am new to surface and I am making a custom component.
I have a data and I want to set its initial value to the value of a prop if it was set.
Something like this:

prop open_by_default, :boolean, default: false
data is_open, :boolean, default: @open_by_default

I did a search and I could not find if this sort of question was already asked.
Thanks in advance. :slight_smile:

You can use update/2 callback, it receives the props as the first param, e.g.

def update(assigns, socket)
  socket = assign(socket, :my_prop, assigns.my_prop)

  {:ok, socket}
end
1 Like

Thanks that did it. :grinning:

1 Like