woocommerce/plugins/woocommerce-blocks/assets/js/base/context/inner-block-configuration-c...

36 lines
806 B
JavaScript

/**
* External dependencies
*/
import { createContext, useContext, useEffect } from '@wordpress/element';
/**
* Internal dependencies
*/
import { assertValidContextValue } from './utils';
const validationMap = {
parentName: {
required: true,
type: 'string',
},
};
const InnerBlockConfigurationContext = createContext( { parentName: null } );
export const useInnerBlockConfigurationContext = () =>
useContext( InnerBlockConfigurationContext );
export const InnerBlockConfigurationProvider = ( { value, children } ) => {
useEffect( () => {
assertValidContextValue(
'InnerBlockConfigurationProvider',
validationMap,
value
);
}, [ value ] );
return (
<InnerBlockConfigurationContext.Provider value={ value }>
{ children }
</InnerBlockConfigurationContext.Provider>
);
};