Add `data-wc-init` directive to Interactivity API (https://github.com/woocommerce/woocommerce-blocks/pull/11458)

This commit is contained in:
Alexandre Lara 2023-10-26 22:59:57 -03:00 committed by GitHub
parent 88b62a46fa
commit f512ea769a
1 changed files with 10 additions and 0 deletions

View File

@ -74,6 +74,16 @@ export default () => {
}
);
// data-wc-init--[name]
directive( 'init', ( { directives: { init }, context, evaluate } ) => {
const contextValue = useContext( context );
Object.values( init ).forEach( ( path ) => {
useEffect( () => {
return evaluate( path, { context: contextValue } );
}, [] );
} );
} );
// data-wc-on--[event]
directive( 'on', ( { directives: { on }, element, evaluate, context } ) => {
const contextValue = useContext( context );