Jolt Hooks

CI/CD codecov jolt_hooks License: MIT

A Flutter hooks integration package for Jolt reactive state management. It provides hook APIs built on flutter_hooks for using Jolt primitives inside Flutter's hook system. Hook-owned resources are disposed when the widget is removed from the tree.

Features

  • Unified API: Class-based hook API with method chaining
  • Type-safe: Uses Dart's type system
  • Automatic disposal: Reactive resources are cleaned up when widgets are disposed
  • Coverage: Supports signals, computed values, effects, watchers, and reactive collections
  • HookWidget / HookBuilder: Works with both patterns

Quick Start

Basic Usage

import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:jolt_hooks/jolt_hooks.dart';
import 'package:jolt_flutter/jolt_flutter.dart';

class CounterWidget extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final count = useSignal(0);
    
    return Scaffold(
      body: JoltBuilder(
        builder: (context) => Text('Count: ${count.value}'),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () => count.value++,
        child: Icon(Icons.add),
      ),
    );
  }
}

Reactive Collections

class TodoListWidget extends HookWidget {
  @override
  Widget build(BuildContext context) {
    final todos = useSignal.list<String>([]);
    
    return Scaffold(
      body: JoltBuilder(
        builder: (context) => Column(
          children: [
            ...todos.value.map((todo) => ListTile(title: Text(todo))),
            ElevatedButton(
              onPressed: () => todos.add('New Todo'),
              child: Text('Add Todo'),
            ),
          ],
        ),
      ),
    );
  }
}

API Reference

Signal Hooks

Hook Description
useSignal(value) Creates a reactive signal with initial value
useSignal.lazy() Creates a lazy signal without initial value
useSignal.list(value) Creates a reactive list signal
useSignal.map(value) Creates a reactive map signal
useSignal.set(value) Creates a reactive set signal
useSignal.iterable(getter) Creates a reactive iterable signal
useSignal.async(source) Creates an async signal for managing async operations
useSignal.persist(initialValue, read, write) Creates a persistent signal with automatic storage

Computed Hooks

Hook Description
useComputed(getter) Creates a computed signal that derives from dependencies
useComputed.writable(getter, setter) Creates a writable computed signal
useComputed.convert(source, decode, encode) Creates a type-converting computed signal

Effect Hooks

Hook Description
useJoltEffect(fn, {lazy}) Creates a reactive effect that runs when dependencies change
useJoltEffect.lazy(fn) Creates an effect that does not run automatically (call run() to start)

Watcher Hooks

Hook Description
useWatcher(sourcesFn, fn, {immediately, when}) Creates a watcher that observes specific sources
useWatcher.immediately(sourcesFn, fn, {when}) Creates a watcher that executes immediately
useWatcher.once(sourcesFn, fn, {when}) Creates a watcher that executes only once

Utility Hooks

Hook Description
useEffectScope({fn}) Creates an effect scope for managing effect lifecycles
useJoltStream(value) Creates a stream from a reactive value
useJoltWidget(builder) Creates a reactive widget that rebuilds when dependencies change

Jolt Hooks is part of the Jolt ecosystem:

Package Description
jolt Core library providing Signals, Computed, Effects, and reactive collections
jolt_flutter Flutter widgets: JoltBuilder, JoltSelector, and ValueNotifier integration
jolt_setup Setup Widget API and Flutter hooks: SetupWidget, SetupMixin, useTextEditingController, useScrollController, etc.
jolt_surge Signal-powered Cubit pattern: Surge, SurgeProvider, SurgeConsumer
jolt_lint Custom lint and code assists: Wrap widgets, convert to/from Signals, Hook conversions

Libraries

jolt_hooks
A Flutter hooks integration package for Jolt reactive state management.