Skip to content

Commit 2ecf5c9

Browse files
author
Claudiu Limban
committed
docs(render-function#template-refs): Make useTemplateRef the default example
1 parent 72587eb commit 2ecf5c9

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

Diff for: src/guide/extras/render-function.md

+13-10
Original file line numberDiff line numberDiff line change
@@ -706,36 +706,39 @@ If the directive is registered by name and cannot be imported directly, it can b
706706

707707
<div class="composition-api">
708708

709-
With the Composition API, template refs are created by passing the `ref()` itself as a prop to the vnode:
709+
With the Composition API, when using [`useTemplateRef()`](/api/composition-api-helpers#usetemplateref) <sup class="vt-badge" data-text="3.5+" /> template refs are created by passing the string value as prop to the vnode:
710710

711711
```js
712-
import { h, ref } from 'vue'
712+
import { h, useTemplateRef } from 'vue'
713713

714714
export default {
715715
setup() {
716-
const divEl = ref()
716+
const divEl = useTemplateRef('my-div')
717717

718-
// <div ref="divEl">
719-
return () => h('div', { ref: divEl })
718+
// <div ref="my-div">
719+
return () => h('div', { ref: 'my-div' })
720720
}
721721
}
722722
```
723723

724-
or (with version >= 3.5)
724+
<details>
725+
<summary>Usage before 3.5</summary>
726+
727+
In versions before 3.5 where useTemplateRef() was not introduced, template refs are created by passing the ref() itself as a prop to the vnode:
725728

726729
```js
727-
import { h, useTemplateRef } from 'vue'
730+
import { h, ref } from 'vue'
728731

729732
export default {
730733
setup() {
731-
const divEl = useTemplateRef('my-div')
734+
const divEl = ref()
732735

733736
// <div ref="divEl">
734-
return () => h('div', { ref: 'my-div' })
737+
return () => h('div', { ref: divEl })
735738
}
736739
}
737740
```
738-
741+
</details>
739742
</div>
740743
<div class="options-api">
741744

0 commit comments

Comments
 (0)