Skip to content

Passing context to functional components #12

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

Closed
eddyerburgh opened this issue Jun 23, 2017 · 4 comments
Closed

Passing context to functional components #12

eddyerburgh opened this issue Jun 23, 2017 · 4 comments

Comments

@eddyerburgh
Copy link
Member

eddyerburgh commented Jun 23, 2017

I propose this API to pass context to functional components:

const context = {
  props: {foo: 'bar'}
}

const wrapper = mount(FunctionalComponent, context)

What are peoples thoughts?

@codebryo
Copy link
Contributor

Agree to 100%, feels natural and allows for customization or extending in the future.
Would you internally turn it to propsData?

@eddyerburgh
Copy link
Member Author

The way I got this working in avoriaz is to mount a component with a render functional that returns the functional component and passes it the context object -

https://github.com/eddyerburgh/avoriaz/blob/master/src/mount.js#L33

I imagine there are problems with doing it like this, but I wanted to get something out there as a canary test.

Maybe we should also allow users to pass props to mount with props instead of propsData, as it's cleaner

@codebryo
Copy link
Contributor

I think it makes sense to make props work for both contexts. And it's a nicer API then using propsData.
Ideally it makes no difference what kind of Component gets mounted as all params will be passed in the same way. Options passed along that don't count for functional components will then be ignored by Vue instance anyway.

@codebryo codebryo mentioned this issue Jun 28, 2017
36 tasks
@eddyerburgh
Copy link
Member Author

Closed with eda39df

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

2 participants