---
title: MARKLESS_STATE_WRITE_IN_COMPUTED
description: "A computed() body writes to state."
sidebar: { hidden: true }
search: { keywords: ["STATE_WRITE_IN_COMPUTED","state write in computed","markless error"] }
pagination: false
---

**Error** from the compiler, while it builds your `.tsrx` files.

## What happened

A `computed()` reads values and returns a result. This one also writes to state, and that write wakes the same computed again.

Markless prints the message, the reason, and a suggestion:

```text
MARKLESS_STATE_WRITE_IN_COMPUTED: `<source>` writes to `<target>` while deriving a computed value. A computed is a graph read, so writing graph state there would re-trigger the same derivation.
A computed is a demand-driven read in the graph; the only effects in the system are compiler-generated DOM updates, so a write inside a derive is a self-waking cycle that cannot resume.
Keep computed() pure. Move graph writes to an event handler and derive only from graph reads.
https://markless.dev/errors/MARKLESS_STATE_WRITE_IN_COMPUTED
```

Words in angle brackets change from case to case.

## How to fix it

Keep `computed()` free of writes. Move the write into an event handler.

## Where it comes from

`@markless/compiler` raises this code. Source:

- [packages/compiler/src/passes/semantic-graph/diagnostics.ts](https://github.com/compiled-run/markless/blob/main/packages/compiler/src/passes/semantic-graph/diagnostics.ts)

Read [how to read a Markless error](/tooling/diagnostics), or go back to [all error codes](/errors).
