---
title: "React, for data: the CocoIndex mental model"
description: "Declare targets as a function of source data. CocoIndex reconciles declared rows as inputs change."
canonical: https://cocoindex.io/react-cocoindex/
last_updated: 2026-11-05
---

# React, for data.

> Declare targets as a function of source data. CocoIndex reconciles declared rows as inputs change.

Last updated: 2026-11-05 · Canonical: https://cocoindex.io/react-cocoindex/

This analogy starts with React: the UI is a function of state. In CocoIndex, your index or table is a function of your source data. When a source item changes, only its rows are rewritten.

[Read the core concepts](https://cocoindex.io/docs/programming_guide/core_concepts/)
[View on GitHub](https://github.com/cocoindex-io/cocoindex)

Figure: Side-by-side illustration: one source item changes. React re-renders App, patches one DOM node and leaves three untouched. CocoIndex re-runs process_file for the changed file while memoization skips the others. The engine reconciles declared rows, upserting one row and leaving three untouched.

## Change a file. Follow the update.

You write the Python. CocoIndex keeps the index in sync.

Interactive demo · simulated

Interactive demo with simulated sample data. A source of 3 files feeds a Python flow with memo=True. The flow runs parse(), summarize() and embed() for each file and writes one row per file, a summary and an embedding, to the doc_rows search index. You can edit refunds.md, add a file, delete a file or change the code. After each change the demo reports how many calls of each function ran, how many results were reused, and which rows were updated or removed.

Build this with your own data.
[Open the docs](https://cocoindex.io/docs/)

## Write it like a component.

Both examples define a function for one item. A parent maps it over items with stable keys. Their memoization compares different inputs.

App.jsx
UI = f(state)

```jsx
import { memo } from "react";

const Row = memo(({ file }) => {
  const summary = summarize(file);
  return <li>{summary}</li>;
});

function App({ files }) {
  return <ul>{files.map((f) => (
    <Row key={f.name} file={f} />
  ))}</ul>;
}
```

`memo` compares each prop by reference. A new `file` object re‑renders the row even when its content is the same.

flow.py
target = f(source)

```python
@coco.fn(memo=True)
async def process_file(file, table):
    name = file.file_path.path.name
    summary = await summarize(file)
    row = DocRow(name, summary)
    table.declare_row(row=row)

@coco.fn
async def app_main(files, table):
    await coco.mount_each(
        process_file,
        files.items(),
        table,
    )
```

`memo=True` compares fingerprints of the file content and the `process_file` code, and keeps the result across runs.

## Compare the two models.

React keeps its tree in memory. CocoIndex records declared target states in its state store. Each run compares against the previous state, including after a restart.

How React concepts correspond to CocoIndex concepts

| Concept | React | CocoIndex |
| --- | --- | --- |
| State | Component state, props and context | Source items and their content fingerprints |
| One unit per item | `files.map(...)` renders one `<Row>` per file | `coco.mount_each(...)` mounts one component per file |
| Identity | `key` on each element, read only by the reconciler | The item key, which gives each component a stable path across runs |
| Diff | The reconciler compares the new element tree with the last one | The engine compares this run's declared rows with the ones it recorded last run |
| Commit | Patch the DOM nodes that differ | Upsert or delete the rows that differ |
| Skip unchanged work | `memo` | `@coco.fn(memo=True)` |
| Cleanup | Unmounted components leave the DOM | Rows from removed source items are deleted |
| Where results land | The DOM | Your target: Postgres, Qdrant, LanceDB, files or Kafka |

## Try it on a local folder.

Write a small flow, change one file, and see the engine re‑run only that file.

[Start with the quickstart](https://cocoindex.io/docs/getting_started/quickstart/)
[View on GitHub](https://github.com/cocoindex-io/cocoindex)

## Sitemap

- [Home](https://cocoindex.io/index.md)
- [Documentation](https://cocoindex.io/docs/)
- [Blog index](https://cocoindex.io/blogs.md)
- [Site index (llms.txt)](https://cocoindex.io/llms.txt)
- [Markdown sitemap](https://cocoindex.io/sitemap.md)
- [XML sitemap](https://cocoindex.io/sitemap.xml)
