useSelector.d.ts 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /// <reference types="react" />
  2. import type { EqualityFn } from '../types';
  3. import type { uSESWS } from '../utils/useSyncExternalStore';
  4. export declare type CheckFrequency = 'never' | 'once' | 'always';
  5. export interface UseSelectorOptions<Selected = unknown> {
  6. equalityFn?: EqualityFn<Selected>;
  7. stabilityCheck?: CheckFrequency;
  8. noopCheck?: CheckFrequency;
  9. }
  10. export interface UseSelector {
  11. <TState = unknown, Selected = unknown>(selector: (state: TState) => Selected, equalityFn?: EqualityFn<Selected>): Selected;
  12. <TState = unknown, Selected = unknown>(selector: (state: TState) => Selected, options?: UseSelectorOptions<Selected>): Selected;
  13. }
  14. export declare const initializeUseSelector: (fn: uSESWS) => void;
  15. /**
  16. * Hook factory, which creates a `useSelector` hook bound to a given context.
  17. *
  18. * @param {React.Context} [context=ReactReduxContext] Context passed to your `<Provider>`.
  19. * @returns {Function} A `useSelector` hook bound to the specified context.
  20. */
  21. export declare function createSelectorHook(context?: import("react").Context<import("../components/Context").ReactReduxContextValue<any, import("redux").AnyAction>>): UseSelector;
  22. /**
  23. * A hook to access the redux store's state. This hook takes a selector function
  24. * as an argument. The selector is called with the store state.
  25. *
  26. * This hook takes an optional equality comparison function as the second parameter
  27. * that allows you to customize the way the selected state is compared to determine
  28. * whether the component needs to be re-rendered.
  29. *
  30. * @param {Function} selector the selector function
  31. * @param {Function=} equalityFn the function that will be used to determine equality
  32. *
  33. * @returns {any} the selected state
  34. *
  35. * @example
  36. *
  37. * import React from 'react'
  38. * import { useSelector } from 'react-redux'
  39. *
  40. * export const CounterComponent = () => {
  41. * const counter = useSelector(state => state.counter)
  42. * return <div>{counter}</div>
  43. * }
  44. */
  45. export declare const useSelector: UseSelector;