useState<T> method

StateHook<T> useState<T>(
  1. T initialValue, [
  2. String? name
])

Create a state hook

Implementation

StateHook<T> useState<T>(T initialValue, [String? name]) {
  if (_hookIndex >= _hooks.length) {
    // Create new hook
    final hook = StateHook<T>(initialValue, name, () {
      scheduleUpdate();
    });
    _hooks.add(hook);
  }

  // Get the hook (either existing or newly created)
  final hook = _hooks[_hookIndex] as StateHook<T>;
  _hookIndex++;

  return hook;
}