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);
  }

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