Provide a way to define different name for prop attribute
See original GitHub issueWhat problem does this feature solve?
In most of cases, it’s not really comfortable to use initialProp
as prop name, for example, or have normalizedProp
inside a component, which takes some passed prop and transforms it. Code looks bloated and reminds more workaround than a good solution.
Having ability to change attribute name of prop would be great. Something like:
rawProp: { attributeName: "prop" }
What does the proposed API look like?
<component size="md"> ... </component>
computed: {
size: {
switch (this.rawSize) { ... } // returns something in case blocks
}
},
props: {
rawSize: {
attributeName: "size",
type: String
}
}
Thus, using any of proposed solutions above, this.size
inside component would return transformed value (for example, h4
or just 4
).
I believe having this feature would be very awesome and help us to write cleaner code.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:55
- Comments:16 (4 by maintainers)
Top Results From Across the Web
Defining Props in React Function Component with Typescript
Another way to define props is to import and use React's Functional Component type, FC for short. Using React.FC is more verbose, but...
Read more >React's props with the same name as their value
Example: Let's say that I have a variable called x : const x = 1 ; and I have a component that has...
Read more >React Props Cheatsheet: 10 Patterns You Should Know
2. React props passed with just their name have a value of true. Every prop must be given an associated value that is...
Read more >Object.defineProperty() - JavaScript - MDN Web Docs
If the old descriptor had its configurable attribute set to false , the property is said to be non-configurable. It is not possible...
Read more >How to customize property names and values with System ...
To set the name of individual properties, use the [JsonPropertyName] attribute. Here's an example type to serialize and resulting JSON:.
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
It seems to me that this would be preferable:
Rather than this:
The external facing prop name should remain as the key in the
props
object regardless of whether an alias is set or not. Adding an alias for internal use should simply require the addition of a property to that prop spec, not changing the property key.Here is an example of an existing
size
prop which the develop later wants to alias within this component:Original proposal:
gets changed to:
My suggestion:
gets added to:
It’s been a while, but I’m going to bring it up again, what’s the status of this feature request? Is it confirmed or already implemented?
The proposed (fjc0k/vue-messenger) does not solve the issue. Again, we simply want an alias to prop names, so we wouldn’t have to write
initialThis
,initialThat
all the time.I’m willing to work on this feature, is it confirmed/implemented?