use<R> static method

  1. @Deprecated('Use `use` instead of `Hook.use`')
R use<R>(
  1. Hook<R> hook
)

Registers a Hook and returns its value.

use must be called within the build method of either HookWidget or StatefulHookWidget. All calls to use must be made outside of conditional statements and always on the same order.

See Hook for more explanations.

Implementation

@Deprecated('Use `use` instead of `Hook.use`')
static R use<R>(Hook<R> hook) {
  assert(HookElement._currentHookElement != null, '''
Hooks can only be called from the build method of a widget that mix-in `Hooks`.

Hooks should only be called within the build method of a widget.
Calling them outside of build method leads to an unstable state and is therefore prohibited.
''');
  return HookElement._currentHookElement!._use(hook);
}