Getting Started
Component Registration
Component Registration
This page assumes you've already read the Components Basics. Read that first if you are new to components.
Watch a free video lesson on Spec School
Global Registration
We can make components available globally in the current Spec application using the app.component() method:
js
If using SFCs, you will be registering the imported .spec files:
js
The app.component()
method can be chained:
js
Local Registration
While convenient, global registration has a few drawbacks:
Global registration prevents build systems from removing unused components (a.k.a "tree-shaking"). If you globally register a component but end up not using it anywhere in your app, it will still be included in the final bundle.
Global registration makes dependency relationships less explicit in large applications. It makes it difficult to locate a child component's implementation from a parent component using it. This can affect long-term maintainability similar to using too many global variables.
Local registration scopes the availability of the registered components to the current component only. It makes the dependency relationship more explicit, and is more tree-shaking friendly.
Expressions in the parent template only have access to the parent scope; expressions in the child template only have access to the child scope.
For each property in the components object, the key will be the registered name of the component, while the value will contain the implementation of the component. The above example is using the ES2015 property shorthand and is equivalent to:
js
Component Name Casing
Throughout the guide, we are using PascalCase names when registering components. This is because:
React Essentials
Building Your Application
TypeScript