UseState<T> class
A ReactterHook that manages a state.
Contains a value of type T
which represents the current state.
When value is different to previous state,
UseState execute update to notify container instance
that has changed and in turn executes onWillUpdate
and onDidUpdate
.
This example produces one simple UseState:
class AppController {
late final likesCount = UseState(0, this);
late final followed = UseState(false, this);
late final text = UseState("", this);
late final user = UseState<User?>(null, this);
late final posts = UseState(<Post>[], this);
AppController() {
likesCount.value += 1;
followed.value = followed.value!;
text.value = "This is a text";
user.value = User(name: "name");
// It's need to force [update] because mantain the previous state
// and the [context] not aware that this state has changed
posts.update(() {
posts.value.add(
Post(
user: user.value,
text: text.value,
),
);
});
}
}
- Inheritance
-
- Object
- ReactterHook
- UseState
Constructors
- UseState(T initialValue)
- A ReactterHook that manages a state.
Properties
- $ → _ReactterHookRegister
-
This variable is used to register ReactterHook
and attach the ReactterState that are defined here.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- initial → T
-
The initial value in state.
final
- instanceAttached → Object?
-
no setterinherited
- isDisposed → bool
-
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- value ↔ T
-
Get current value state
getter/setter pair
Methods
-
attachTo(
Object instance) → void -
Attaches an object instance to this state.
inherited
-
detachInstance(
) → void -
Detaches an object instance to this state.
inherited
-
dispose(
) → void -
Called when this object is removed
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refresh(
) → void -
It's used to notify listeners that the state has been updated.
It is typically called after making changes to the state object.
inherited
-
reset(
) → void - Reset the state to initial value
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
[covariant Function? callback]) → void -
Executes
callback
, and notify the listeners about to update.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited