useHook<T> function
Creates a hook that persists across rebuilds and hot reloads.
Hooks are matched during hot reload by their runtime type and position in the sequence. If the hook sequence changes:
- Matching hooks are reused and SetupHook.reassemble is called
- Mismatched hooks trigger unmount of all subsequent hooks
- New hooks are created and SetupHook.mount is called
Example:
class CounterHook extends SetupHook<int> {
@override
int build() => 0;
@override
void mount() {
print('Hook mounted');
}
@override
void unmount() {
print('Hook unmounted');
}
}
// In setup:
final counter = useHook(CounterHook());
Implementation
T useHook<T>(SetupHook<T> hook) => JoltSetupContext.current!._useHook(hook);