Surface: how to "default" a data assign


I try to learn Surface. So I came across the Counter example (from here: Surface) :

defmodule Counter do
  use Surface.LiveComponent

  data count, :integer, default: 0

  def render(assigns) do
      <h1 class="title">
        <button class="button is-info" :on-click="dec">
        <button class="button is-info" :on-click="inc">

  def handle_event("inc", _value, socket) do
    {:noreply, update(socket, :count, &(&1 + 1))}

  def handle_event("dec", _value, socket) do
    {:noreply, update(socket, :count, &(&1 - 1))}

In the example the count is set to 0 by default.

Let’s assume I want to use the counter on different locations:

 <Counter id="C1"  />
 <Counter id="C2"  />
 <Counter id="C3"  />

In C1 it should start at 0, in C2 at 4 and in C3 at 300.

So how can I let the component start with different values?

What I tried so far:
I can set “prop” to a value in the component “call”, but not “data assigns”.
I then tried to set a prop and then copy the value during mount to the data assign. That didn’t work.

You could define count as a prop and then implement update/2 like this:

prop count, :integer, default: 0

def update(assigns, socket) do
  {:ok, assign(socket, assigns)}

Then you could initalize your counter like this:

<Counter id="c1" count={10} />
<Counter id="c2" count={5} />
<Counter id="c3" count={0} />

Not sure if that is the correct way, but it worked for me, when I experimented with Surface.

Yea, it works. Not declaring it as “data” but as “prop” did the trick. Thanks.