add `options` property to the render context of functional component
See original GitHub issueWhat problem does this feature solve?
Custom properties in the options of functional component can’t be accessed easily.
What does the proposed API look like?
In the render function of functional component, options can be accessed by context.options
, just like vm.$options
(https://vuejs.org/v2/api/index.html#vm-options)
related issue #7492
Issue Analytics
- State:
- Created 5 years ago
- Reactions:8
- Comments:13 (5 by maintainers)
Top Results From Across the Web
Components and Props - React
Rendering a Component · We call root.render() with the <Welcome name="Sara" /> element. · React calls the Welcome component with {name: 'Sara'} as...
Read more >How to use React Context like a pro - Devtrium
Use React Context with a custom Provider. First, we'll create a UserContextProvider component inside of a new file called UserContext.jsx . This ...
Read more >Render Functions & JSX | Vue.js
To create a functional component we use a plain function, rather than an options object. The function is effectively the render function for...
Read more >Functional Components in Vue.js - DigitalOcean
The context argument you see on the render function is known as the render context. It's an object containing the following properties: props ......
Read more >Using React Context with Functional Components | by Dan Fyfe
Pretty simple. All we have done is made an InfoContainer component that contains a ListContainer and a GraphContainer. We then wrapped both of...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Sure! Disclaimer though, I’m fairly new to vue. I have pretty extensive experience in other front end frameworks, but I’m new to adopting vue. There’s a very real chance I’m doing something ridiculous and unintuitive, but the use case doesn’t strike me that way, personally.
Suppose I have a mixin that takes a custom property “types” from a component definition, assuming its present, and checks for matching attributes on the component’s host element. It then concatenates a string of styles, derived from the attributes specified on the component element that match a type specified in the component definition. Here’s how I might do it (I’m using styled components. Hopefully you’re familiar with the library):
So, suppose this is my component:
And here’s my
IsTyped
mixin:Unfortunately, this does not work. Because
$options
is not on thecontext
object provided to the render function.My initial idea was to let functional components can be extended dynamically. Extended components have the same render logic but different options. Now I think I have found another workaround: using a factory function.