MARKLESS_STATE_STALE_LOCAL_WRITE
An event handler writes a plain variable that the markup reads, so the page never changes.
Error from the compiler, while it builds your .tsrx files.
What happened
A handler changes a plain let, and the markup shows that variable. The markup reads it only once, when the page first renders, so the click changes nothing on screen.
Markless prints the message, the reason, and a suggestion:
MARKLESS_STATE_STALE_LOCAL_WRITE: Cannot write to "<target>" from a handler because the template reads the component local "<name>" only during initial render.
Component bodies run for initial render only. Template reads re-render after events only when they subscribe through state(), so this handler write would leave the UI stale after resume.
Move "<name>" into state(), then write <name>++ so Markless can serialize the cell and update subscribed DOM.
https://markless.dev/errors/MARKLESS_STATE_STALE_LOCAL_WRITE
Words in angle brackets change from case to case.
How to fix it
Wrap the value in state(). Then the page updates every time the handler writes it.
let count = state(0);
<button onClick={() => count++}>{count}</button>
Where it comes from
@markless/compiler raises this code. Source:
Read how to read a Markless error, or go back to all error codes.
