File "components-extension-context.js"

Full Path: /home/siazco/grocery.siazco.se/wp-content/plugins/yith-woocommerce-wishlist/assets/js/src/utils/components-extension-context.js
File size: 746 bytes
MIME-type: text/x-java
Charset: utf-8

import { createContext, useContextSelector } from 'use-context-selector';

const ComponentsExtensionContext = createContext( {} );

export const useComponentExtensionsContext = () => useContextSelector( ComponentsExtensionContext, state => state );
export const useComponentsExtension = ( hookName ) => {
	const extensions = useComponentExtensionsContext();
	if ( ! extensions || ! (extensions[ hookName ] || null) ) {
		const EmptyFragment = () => <></>;
		EmptyFragment.isEmpty = true;

		return EmptyFragment;
	}

	return extensions[ hookName ];
}

export const ComponentsExtensionProvider = ( { children, extensions } ) => (
	<ComponentsExtensionContext.Provider value={ extensions }>
		{ children }
	</ComponentsExtensionContext.Provider>
);