# \ ``` The code inside is compiled as the content of the component's `setup()` function. This means that unlike normal ` ``` Imports are exposed in the same fashion. This means you can directly use an imported helper function in template expressions without having to expose it via the `methods` option: ```vue ``` ## Reactivity {#reactivity} Reactive state needs to be explicitly created using [Reactivity APIs](./reactivity-core). Similar to values returned from a `setup()` function, refs are automatically unwrapped when referenced in templates: ```vue ``` ## Using Components {#using-components} Values in the scope of ` ``` Think of `MyComponent` as being referenced as a variable. If you have used JSX, the mental model is similar here. The kebab-case equivalent `` also works in the template - however PascalCase component tags are strongly recommended for consistency. It also helps differentiating from native custom elements. ### Dynamic Components {#dynamic-components} Since components are referenced as variables instead of registered under string keys, we should use dynamic `:is` binding when using dynamic components inside ` ``` Note how the components can be used as variables in a ternary expression. ### Recursive Components {#recursive-components} An SFC can implicitly refer to itself via its filename. E.g. a file named `FooBar.vue` can refer to itself as `` in its template. Note this has lower priority than imported components. If you have a named import that conflicts with the component's inferred name, you can alias the import: ```js import { FooBar as FooBarChild } from './components' ``` ### Namespaced Components {#namespaced-components} You can use component tags with dots like `` to refer to components nested under object properties. This is useful when you import multiple components from a single file: ```vue ``` ## Using Custom Directives {#using-custom-directives} Globally registered custom directives just work as normal. Local custom directives don't need to be explicitly registered with ` ``` If you're importing a directive from elsewhere, it can be renamed to fit the required naming scheme: ```vue ``` ## defineProps() & defineEmits() {#defineprops-defineemits} To declare options like `props` and `emits` with full type inference support, we can use the `defineProps` and `defineEmits` APIs, which are automatically available inside ` ``` - `defineProps` and `defineEmits` are **compiler macros** only usable inside ` ``` When a parent gets an instance of this component via template refs, the retrieved instance will be of the shape `{ a: number, b: number }` (refs are automatically unwrapped just like on normal instances). ## defineOptions() {#defineoptions} - Only supported in 3.3+ This macro can be used to declare component options directly inside ` ``` - This is a macro. The options will be hoisted to module scope and cannot access local variables in ` ``` ## `useSlots()` & `useAttrs()` {#useslots-useattrs} Usage of `slots` and `attrs` inside ` ``` `useSlots` and `useAttrs` are actual runtime functions that return the equivalent of `setupContext.slots` and `setupContext.attrs`. They can be used in normal composition API functions as well. ## Usage alongside normal ` ``` Support for combining ` ``` In addition, the awaited expression will be automatically compiled in a format that preserves the current component instance context after the `await`. :::warning Note `async setup()` must be used in combination with [`Suspense`](/guide/built-ins/suspense.html), which is currently still an experimental feature. We plan to finalize and document it in a future release - but if you are curious now, you can refer to its [tests](https://github.com/vuejs/core/blob/main/packages/runtime-core/__tests__/components/Suspense.spec.ts) to see how it works. ::: ## Generics {#generics} Generic type parameters can be declared using the `generic` attribute on the ` ``` The value of `generic` works exactly the same as the parameter list between `<...>` in TypeScript. For example, you can use multiple parameters, `extends` constraints, default types, and reference imported types: ```vue ``` In order to use a reference to a generic component in a `ref` you need to use the [`vue-component-type-helpers`](https://www.npmjs.com/package/vue-component-type-helpers) library as `InstanceType` won't work. ```vue