useDispatch.d.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132
  1. import type { Action, AnyAction, Dispatch } from 'redux';
  2. import type { Context } from 'react';
  3. import type { ReactReduxContextValue } from '../components/Context';
  4. /**
  5. * Hook factory, which creates a `useDispatch` hook bound to a given context.
  6. *
  7. * @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
  8. * @returns {Function} A `useDispatch` hook bound to the specified context.
  9. */
  10. export declare function createDispatchHook<S = unknown, A extends Action = AnyAction>(context?: Context<ReactReduxContextValue<S, A>>): <AppDispatch extends Dispatch<A> = Dispatch<A>>() => AppDispatch;
  11. /**
  12. * A hook to access the redux `dispatch` function.
  13. *
  14. * @returns {any|function} redux store's `dispatch` function
  15. *
  16. * @example
  17. *
  18. * import React, { useCallback } from 'react'
  19. * import { useDispatch } from 'react-redux'
  20. *
  21. * export const CounterComponent = ({ value }) => {
  22. * const dispatch = useDispatch()
  23. * const increaseCounter = useCallback(() => dispatch({ type: 'increase-counter' }), [])
  24. * return (
  25. * <div>
  26. * <span>{value}</span>
  27. * <button onClick={increaseCounter}>Increase counter</button>
  28. * </div>
  29. * )
  30. * }
  31. */
  32. export declare const useDispatch: <AppDispatch extends Dispatch<AnyAction> = Dispatch<AnyAction>>() => AppDispatch;