Comment

Comment by alsiola

I consider this example fundamentally broken, in a non-obvious way that reflects, in my opinion, a poor API choice.

  <script>
    let numbers = $state([1, 2, 3, 4]);

    function addNumber() {
      numbers.push(numbers.length + 1);
    }

    const sum = numbers.reduce((x, y) => x + y, 0);
  </script>

  <p>{numbers.join(' + ')} = {sum}</p>

  <button onclick={addNumber}>
   Add a number
  </button>
parent alsiola 1 year ago

No comments yet

Be the first to share your thoughts.

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton