You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The useState hook returns a ValueNotifier which is a wrapper class for the value.
final counter =useState(0);
// Reading
counter.value
// Updating
counter.value++
A ValueNotifier adds an extra layer to access the actual value. This was inevitable due to the lack of destructuring features of Dart.
Dart 3 has introduced the Pattern which allows us to destructure a list, map, or class with the new syntax. Dart 3 also comes with a new type Record which allows returning multiple values from a function without a wrapper class.
I propose to change the return value to a Record so that we can write code like the below:
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
The
useState
hook returns aValueNotifier
which is a wrapper class for thevalue
.A
ValueNotifier
adds an extra layer to access the actualvalue
. This was inevitable due to the lack of destructuring features of Dart.Dart 3 has introduced the Pattern which allows us to destructure a list, map, or class with the new syntax. Dart 3 also comes with a new type
Record
which allows returning multiple values from a function without a wrapper class.I propose to change the return value to a
Record
so that we can write code like the below:The advantages of this new syntax are:
• Separated ways of reading and updating the value
• Succient one-line declaration
• More React-like
This would attract more developers who have a React background. I'd like to discuss if this breaking change is worth it.
Beta Was this translation helpful? Give feedback.
All reactions