If I take the code at face value, the regular way to do this would be like this:
#let id = state("refsection-id", "ref")
#id.update(x => x + "_1")
#context {
// <-- here
let my-id = id.get()
}
state.updatedoes not needcontextcontextis acquired after the update so thegetwill see the update. Not in the first layout iteration, but the state value will be available there as soon as possible
NOTE that in your example, athere, thegetwill never see the updated state value, because the context is acquired before the update happens, and this fact is not about layout iterations, just the rules ofstate.
If you must put the update into the same context block then I would do something like this:
#let id = state("refsection-id", "ref")
#context {
let updater = x => x + "_1"
id.update(updater)
let my-id = updater(id.get())
}
As you know we can’t and should not store my-id into a state.update but we can do parallel mappings of the state value this way.
As a general note, I assume you want to use a counter, not state to count refsections. But the logic above is analogous when using counter.