16 lines
465 B
TypeScript
16 lines
465 B
TypeScript
// Copyright 2020-2021 Signal Messenger, LLC
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
import { ActionCreatorsMapObject, bindActionCreators } from 'redux';
|
|
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]);
|
|
};
|