Props & data

Phoenix Streams

A stream assign arrives in React as an array with __dom_id

  • stream/4
  • __dom_id

Key concepts

stream/4 manages a large or growing collection without keeping every item in LiveView memory or re-sending the whole list on every change. Assigning a stream to a prop hands React the current list as a plain array — inserts, updates, deletes and resets all arrive as ordinary prop diffs.

    How it works

    Every item in a stream carries a __dom_id key that LiveReact adds — a stable id derived from Phoenix's own stream ref, not from any field of the message itself. Use it, not message.id, as the React key: it stays correct across stream_insert/3, stream_delete/3 and a full reset: true replacement, which is exactly what a stream's own DOM-patching semantics guarantee on the server side.

    stream_insert(socket, :messages, message, update_only: true) patches an item that's already on the page without moving or re-inserting it — that's what backs the "Edit" button, in contrast to a plain insert for "Send" and a full reset: true for "Replace all".