import type { ThunkDispatch, UnknownAction } from '@reduxjs/toolkit';
import { useDispatch } from 'react-redux';

// Generic dispatch type used by HostsTree internals. The actual app's
// `AppDispatch` is a subtype (it inherits the thunk middleware from
// `configureStore`), so consumers don't have to do anything special.
export type AppDispatchLike = ThunkDispatch<unknown, unknown, UnknownAction>;

// Typed dispatch hook for HostsTree components, so call sites don't have to
// repeat `useDispatch<AppDispatchLike>()`.
export const useHostTreeDispatch = () => useDispatch<AppDispatchLike>();
