2021-09-17 22:24:21 +00:00
|
|
|
// Copyright 2020-2021 Signal Messenger, LLC
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
2021-10-26 19:15:33 +00:00
|
|
|
import type { ActionCreatorsMapObject } from 'redux';
|
|
|
|
import { bindActionCreators } from 'redux';
|
2021-09-17 22:24:21 +00:00
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
import { useMemo } from 'react';
|
|
|
|
|
|
|
|
export const useBoundActions = <T extends ActionCreatorsMapObject>(
|
|
|
|
actions: T
|
|
|
|
): T => {
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
return useMemo(() => {
|
|
|
|
return bindActionCreators(actions, dispatch);
|
|
|
|
}, [actions, dispatch]);
|
|
|
|
};
|