question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Provide a way to define different name for prop attribute

See original GitHub issue

What 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:open
  • Created 5 years ago
  • Reactions:55
  • Comments:16 (4 by maintainers)

github_iconTop GitHub Comments

25reactions
hrobertsoncommented, Jan 18, 2019

It seems to me that this would be preferable:

props: {
  size: {
    type: String,
    alias: "rawSize"
  }
}

Rather than this:

props: {
  rawSize: {
    type: String,
    propName: "size"
  }
}

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:

props: {
  size: {
    type: String
  }
}

gets changed to:

props: {
  rawSize: {
    type: String,
    propName: "size"
  }
}

My suggestion:

props: {
  size: {
    type: String
  }
}

gets added to:

props: {
  size: {
    type: String,
    alias: "rawSize"
  }
}
11reactions
jbieliauskascommented, Oct 13, 2018

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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found