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 context
of ReactterContext
that has changed and in turn executes onWillUpdate
and onDidUpdate
.
This example produces one simple UseState:
class AppContext extends ReactterContext {
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);
AppContext() {
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,
),
);
});
}
}
See also:
- ReactterContext, a context that contains any logic and allowed react when any change the ReactterHook.
- Inheritance
-
- Object
- ReactterHookManager
- ReactterHook
- UseState
Constructors
- UseState(T initial, [ReactterHookManager? context])
Properties
Methods
-
dispose(
) → void -
Called when this object is removed
inherited
-
listenHooks(
List< ReactterHook> hooks) → void -
Suscribes to all
hooks
given.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
refresh(
) → void -
Forces update and notifies to listeners that it did update
inherited
-
reset(
) → void - Reset the state to initial value
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
[covariant Function? callback]) → void -
Executes
fnUpdate
, and notify the listeners about to update.inherited -
updateAsync(
[covariant Function? callback]) → Future< void> -
Executes
fnUpdate
, and notify the listeners about to update as async way.inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited