LogoSignals.dart
Copy Markdown
rodydavis/signals.dart 999999

useSignalProvider

A custom hook to retrieve a generic signal from a SignalProvider ancestor higher up in the widget tree.

A custom hook to retrieve a generic signal from a SignalProvider ancestor higher up in the widget tree.

Under the hood, this uses the BuildContext to look up the provider and registers a reactive dependency.

Supports standard core signals from package:signals_core/signals_core.dart as well as Flutter-native signals.

Example Usage#

class CounterDisplayWidget extends HookWidget {
  const CounterDisplayWidget({super.key});

  @override
  Widget build(BuildContext context) {
    final counter = useSignalProvider<Signal<int>>();
    if (counter == null) return const Text('Not found');
    return Text('Value: ${counter.value}');
  }
}