Affects Version/s: None
Fix Version/s: None
Component/s: JS APIs and Utilities
WISHLIST ITEM — We don't yet have an immediate need for this, but it is an obvious potential improvement, so I want to make a note of it.
Sibling issue to:
Obvious counterpart to LPS-131052 (see that one for more context), the proposal here is to accept the "functional updater" pattern that is familiar from React's useState hook (docs) in our own useLiferayState hook:
The usual gotchas about stale closures apply. In practice if you have a counter-like value in state, the functional updater pattern is one you will want, unless you're doing a reset back to a fixed value like I am in the example.