Skip to content

Commit 474742c

Browse files
docs (#136): include attribute fallthrough updates for functional components (#141)
* docs (#136): include attribute fallthrough updates * docs: improve clarity of statement Co-authored-by: Natalia Tepluhina <tarya.se@gmail.com> * docs: remove extraneous word Co-authored-by: Natalia Tepluhina <tarya.se@gmail.com> Co-authored-by: Natalia Tepluhina <tarya.se@gmail.com>
1 parent f9086cf commit 474742c

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

Diff for: src/guide/migration/functional-components.md

+41-5
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
In terms of what has changed, at a high level:
66

77
- Performance gains from v2 for functional components are now negligible in v3, so we recommend just using stateful components
8-
- `functional` attribute on single-file component `<template>` is deprecated
98
- Functional components can only be created using a plain function that receives `props` and `context` (i.e., `slots`, `attrs`, `emit`)
9+
- **DEPRECATED:** `functional` attribute on single-file component (SFC) `<template>` is deprecated
10+
- **DEPRECATED:** `{ functional: true }` option in components created by functions is deprecated
1011

11-
For a more in-depth explanation, read on!
12+
For more information, read on!
1213

1314
## Introduction
1415

15-
In Vue 2, functional components had primary use cases:
16+
In Vue 2, functional components had two primary use cases:
1617

1718
- as a performance optimization, because they initialized much faster than stateful components
1819
- to return multiple root nodes
@@ -53,12 +54,19 @@ export default {
5354
props: ['level']
5455
}
5556
</script>
56-
5757
```
5858

5959
## Current Syntax
6060

61-
Now in Vue 3, the only way to create a functional component is with a plain function that receives `props` and a `context` object that contains `attrs`, `slots`, and `emit` options:
61+
### Components Created by Functions
62+
63+
Now in Vue 3, all functional components are created with a plain function. In other words, there is no need to define the `{ functional: true }` component option.
64+
65+
They will receive two arguments: `props` and `context`. The `context` argument is an object that contains a component's `attrs`, `slots`, and `emit` properties.
66+
67+
In addition, rather than implicitly provide provide `h` in a `render` function, `h` is now imported globally.
68+
69+
Using the previously mentioned example of a `<dynamic-heading>` component, here is how it looks now.
6270

6371
```js
6472
import { h } from 'vue'
@@ -72,6 +80,34 @@ DynamicHeading.props = ['level']
7280
export default GreetingMessage
7381
```
7482

83+
### Single File Components (SFCs)
84+
85+
In v3, the performance difference between stateful and functional components has been drastically reduced and will be insignificant in most use cases. As a result, the migration path for developers using `functional` on SFCs is to remove the attribute. No additional work required.
86+
87+
Using our `<dynamic-heading>` example from before, here is how it would look now.
88+
89+
```js{1}
90+
<template>
91+
<component
92+
v-bind:is="`h${props.level}`"
93+
v-bind="$attrs"
94+
/>
95+
</template>
96+
97+
<script>
98+
export default {
99+
props: ['level']
100+
}
101+
</script>
102+
```
103+
104+
The main differences are that:
105+
106+
1. `functional` attribute removed on `<template>`
107+
1. `listeners` are now passed as part of `$attrs` and can be removed
108+
109+
## Next Steps
110+
75111
For more information on the usage of the new functional components and the changes to render functions in general, see:
76112

77113
- [Migration: Render Functions](TODO)

0 commit comments

Comments
 (0)