UseContext<T extends ReactterContext> class

A ReactterHook that helps to get the context of ReactterContext by T with or without id.

final appContextHook = UseContext<AppContext>();
final appContextWithIdHook = UseContext<AppContext>('uniqueId');

The context that you need to get, to must be created by ReactterInstanceManager:

Reactter.create<AppContext>(() => AppContex());

or created by ReactterProvider of flutter_reactter

You can get instance, using instance getter:

final appContextHook = UseContext<AppContext>();
print(appContextHook.instance);

instance returns null, when the instance is not found or it hasn't created yet.

To wait for the instance to be created, you need to use the UseEffect hook.

final appContextHook = UseContext<AppContext>(null, this);
print(appContextHook.instance); // return null

UseEffect(() {
  print(appContextHook.instance); // return instance of AppContext
}, [appContextHook]);

You should call dispose when it's no longer needed.

See also:

Inheritance

Constructors

UseContext({String? id, ReactterContext? context})

Properties

context ReactterContext?
final
hashCode int
The hash code for this object.
no setterinherited
id String?
final
instance → T?
no setter
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

dispose() → dynamic
Call when this hook is no longer needed.
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
toString() String
A string representation of this object.
inherited
update([Function? callback]) → void
First, invokes the subscribers callbacks of the willUpdate event.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited