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

[Feature Request]: exp props syntax #161

Closed
MaxmaxmaximusGitHub opened this issue Apr 26, 2020 · 1 comment
Closed

[Feature Request]: exp props syntax #161

MaxmaxmaximusGitHub opened this issue Apr 26, 2020 · 1 comment

Comments

@MaxmaxmaximusGitHub
Copy link

MaxmaxmaximusGitHub commented Apr 26, 2020

Summary

Add exp prop syntax

Basic example

let prop = "propName"
<div [prop]="value"></div>

Alternatives

rest style

let prop = "propName"
<div {...{[prop]: "value"}}></div>

variable style

let prop = "propName"
let expProps = {[prop]: "value"}
<div {...expProps}></div>

Motivation

Motivation is the same as the creators of dynamic props in javascript: sugar.
Since jsx is sugar on top of javascript, and javascript has exp props, we need to add exp props to jsx tags, to support javascript semantics.

Detailed design

this:

let prop = "propName"

<div [prop]={ 1 + 2 } className="box"></div>

compile to:

let prop = "propName"

React.createElement("div", {
  [prop]    : 1 + 2,
  className : "box"
})

Usage example

function Component () {
  const inputValue = useInputValue('#input')
  const inputValue2 = useInputValue('#input2')

  return <div [inputValue]={inputValue2}><div>
}
@gaearon
Copy link
Member

gaearon commented Apr 28, 2020

Thanks for the issue.
This is more of a JSX feature request, than React.

It has already been proposed in facebook/jsx#108, so let's track it there. There was also a different variation in facebook/jsx#21.

I think it's plausible something like this will make it into a future version. However, there is also less demand for this particular feature as people adopt static typing and it wouldn't work that well anyway.

@gaearon gaearon closed this as completed Apr 28, 2020
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