UseEffect constructor

UseEffect(
  1. Function callback,
  2. List<ReactterHook> dependencies, [
  3. ReactterContext? context
])

Implementation

UseEffect(
  this.callback,
  this.dependencies, [
  this.context,
]) : super(context) {
  listenHooks(dependencies);

  if (context == null) {
    _watchDependencies();
    return;
  }

  if (context is DispatchEffect) {
    _runCallbackAndWatchDependencies(null, null);
  }

  Reactter.on(
    context,
    Lifecycle.didMount,
    _runCallbackAndWatchDependencies,
  );
  Reactter.on(
    context,
    Lifecycle.willUnmount,
    _runCleanupAndUnwatchDependencies,
  );
  Reactter.one(context, Lifecycle.destroyed, (_, __) => dispose());
}