diff --git a/lib/hooks/ops-hooks.js b/lib/hooks/ops-hooks.js new file mode 100644 --- /dev/null +++ b/lib/hooks/ops-hooks.js @@ -0,0 +1,21 @@ +// @flow + +import * as React from 'react'; + +import type { MessageID } from '../types/db-ops-types.js'; +import type { SuperAction } from '../types/redux-types.js'; +import { useDispatch } from '../utils/redux-utils.js'; + +function useDispatchWithMessageID(): ( + action: SuperAction, + messageID: MessageID, +) => mixed { + const dispatch = useDispatch(); + return React.useCallback( + (action: SuperAction, messageID: MessageID) => + dispatch({ ...action, messageID }), + [dispatch], + ); +} + +export { useDispatchWithMessageID };