Get component instance count

webflow.getInstanceCount(component)

Gets the number of instances of a component.

Syntax

1webflow.getInstanceCount(component: Component): Promise<number>

Returns

Promise<number>

A Promise that resolves to the number of instances of the component across the entire site.

Example

1// Audit component usage across the site
2const components = await webflow.getAllComponents();
3for (const component of components) {
4 const name = await component.getName();
5 const count = await component.getInstanceCount();
6 console.log(`${name}: ${count} instances`);
7}
8// Guard against removing a component that's still in use
9const hero = components[0];
10const instanceCount = await hero.getInstanceCount();
11if (instanceCount > 0) {
12 console.log(`Cannot safely remove — ${instanceCount} instances exist`);
13} else {
14 await webflow.unregisterComponent(hero);
15}

Designer Ability

Checks for authorization only

Designer AbilityPermissionLocaleBranchWorkflowSitemode
canAccessCanvasanyanyanyanyany