A handler changes a value that is not state
The message
MARKLESS_HANDLER_WRITES_RENDER_LOCAL: The `<handlerLabel>` handler <how>. `<localName>` is a const of the component body, and the browser builds it again from its definition each time the handler runs, so any change would be lost before the next run.
The component body runs only during the initial render. A handler that reads a body const carries its definition and builds a fresh copy when it runs; only state() keeps a value between runs. A method the compiler cannot prove only reads the value counts as a change.
Keep data that changes in state(): `const <localName> = state(...)`, and assign a new value to it, for example a copy with the change applied.
https://markless.dev/errors/MARKLESS_HANDLER_WRITES_RENDER_LOCALWords in angle brackets change from case to case.
Why
A handler that reads a const from the component body builds a fresh copy of it each time it runs. Changing that copy, with list.push(...), names.set(...) or box.count = 1, would be lost before the next run. A method the compiler cannot prove only reads the value counts as a change.
Fix
Keep data that changes in state(), and assign it a new value: a copy with the change applied.
let list = state([1, 2]);<button onClick={() => (list = [...list, list.length + 1])}>Add</button>