Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ref doesn't work on functional components. #6829

Closed
HakurouKen opened this issue Oct 16, 2017 · 2 comments
Closed

Ref doesn't work on functional components. #6829

HakurouKen opened this issue Oct 16, 2017 · 2 comments

Comments

@HakurouKen
Copy link

HakurouKen commented Oct 16, 2017

Version

2.5.2

Reproduction link

https://jsfiddle.net/d2pj7wuo/

Steps to reproduce

Open the JSFiddle link, then check the console.

What is expected?

The child functional component can be attached by this.$refs , or give a warning in development environment when attribute ref is set on a functional component.

What is actually happening?

this.$refs of parent componet is an empty object.


There's a similar issues for React stateless components. A functional component will not actually generate a VueComponent instance, instead of attaching the dom element directly, a warn or an error thrown may be a better choice.

@sqal
Copy link
Contributor

sqal commented Oct 16, 2017

It doesn't work because you are not passing component's data to the root vnode, which contains ref reference. Simply do return h('p', context.data, 'text');

Fixed repro: https://jsfiddle.net/d2pj7wuo/1/

@vuejs vuejs deleted a comment from shyn0121 Oct 16, 2017
@vuejs vuejs deleted a comment from shyn0121 Oct 16, 2017
@vuejs vuejs deleted a comment from shyn0121 Oct 16, 2017
@vuejs vuejs deleted a comment from shyn0121 Oct 16, 2017
@alejandroiglesias
Copy link

alejandroiglesias commented Mar 19, 2019

@sqal how about using refs in a functional component (not referencing a functional component as in the fiddle)? That is also not working for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants