/**
 * Copyright IBM Corp. 2020, 2026
 *
 * This source code is licensed under the Apache-2.0 license found in the
 * LICENSE file in the root directory of this source tree.
 */

import { FilterContext } from "../FilterProvider.js";
import { useContext, useEffect } from "react";

//#region src/components/Datagrid/Datagrid/addons/Filtering/hooks/useSubscribeToEventEmitter.js
/**
* Copyright IBM Corp. 2022, 2023
*
* This source code is licensed under the Apache-2.0 license found in the
* LICENSE file in the root directory of this source tree.
*/
/**
* Subscribes to the filter event emitter
* @param  {string} type - the type of event to call
* @param  {Function} callback - a callback to run when the event is dispatched
*/
const useSubscribeToEventEmitter = (type, callback) => {
	const { EventEmitter } = useContext(FilterContext);
	useEffect(function subscribeToEmitter() {
		EventEmitter.subscribe(type, callback);
	});
};

//#endregion
export { useSubscribeToEventEmitter as default };