I wonder what’s the intended future for two conventions of using
state
(apart from
+
operator):
Copy code
var foo by +state { 0 } // property delegation to state
var (foo, setFoo) = +state { 0 } // destructuring state
Is the second-one just a React/JS gimmick because “we can” or is it really useful in some use-cases?
➕ 5
r
Robert Menke
05/12/2019, 9:58 PM
I could see use for
setFoo
in cases where you might want to use techniques like currying or function composition. How do you define
setFoo
with the
+state
api?
j
jim
05/13/2019, 5:57 PM
The two variants are roughly equivalent; I don't think there is a compelling reason to prefer one over the other. The property delegation might be slightly preferable because we would more naturally warn if you attempt to mutate that