woocommerce/plugins/woocommerce-admin/client/customize-store/assembler-hub/hooks/use-insert-pattern-by-name.ts

30 lines
562 B
TypeScript
Raw Normal View History

/**
* Internal dependencies
*/
import { useInsertPattern } from './use-insert-pattern';
import { usePatterns } from './use-patterns';
export const useInsertPatternByName = () => {
const { blockPatterns, isLoading } = usePatterns();
const { insertPattern } = useInsertPattern();
const insertPatternByName = ( name: string ) => {
if ( isLoading ) {
return;
}
const pattern = blockPatterns.find( ( p ) => p.name === name );
if ( ! pattern ) {
return;
}
insertPattern( pattern );
};
return {
insertPatternByName,
isLoading,
};
};