UseContext<T extends ReactterContext> constructor

UseContext<T extends ReactterContext>({
  1. String? id,
  2. ReactterContext? context,
})

Implementation

UseContext({
  this.id,
  this.context,
}) : super(context) {
  if (context != null) {
    UseEvent.withInstance(context)
        .one(Lifecycle.destroyed, (_, __) => dispose);
  }

  _getInstance();

  UseEvent<T>(id).on(Lifecycle.destroyed, _onInstance);

  if (instance != null) return;

  UseEvent<T>(id).on(Lifecycle.initialized, _onInstance);
  UseEvent<T>(id).on(Lifecycle.willMount, _onInstance);
}