-
Notifications
You must be signed in to change notification settings - Fork 132
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
JSX 2.0 #65
Comments
I would be interested in having a real story for comments e.g. #7. |
Also, having an actual syntax for fragments would be a very welcome feature (e.g. the previously talked about |
what would it be for fragments? const frag = <>
<div>hello</div>
<div>world</div>
</>;
// vs
const frag = [
<div>hello</div>,
<div>world</div>
]; then it's the same, you'll need comments is a good idea, |
There should be a setting to turn it on for dev / off for production in the implementing libraries. |
We need more restrictions on how JSX can be written. People are using terrible practices and teaching it to others. Example: child props should only be passed into components via childProps, otherwise it's a mess. There are so many ways to do things but few even ask if they should do it that way. |
Something like Angular |
Most of these changes wouldn't affect my codebase since I use them sparingly. Comments however would be great. It's kind of insane that normal javascript commenting isn't supported even with all the crazy tool chains we are running. |
I'd say allow adjacent elements without enclosing tag, really hate additional <div>
<ComponentA />
<ComponentB />
</div> |
@jasonslyvia That's what fragments are for. |
Would be nice to have something like how Adobe/Apache Flex deals with conditional inclusion of components. It is refered to as state in Flex world. You can assign a child component a state name and then when you set the parent components state it hides/shows child components as appropriate |
Hi guys! What do you think about this idea? https://github.com/alexander-shvets/cascading-component-layers-react |
@syranide It would be better if it could be solved in syntax level. |
|
@mohsen1 our convention for our stateless functional components is to use:
which works pretty well for us. It's pretty clean as long as your outer component props are a clear pre-calculated boolean for show/hide. Because your components don't have any business logic, this should be fine already, right? ;) edit: the ternary allows us to include an alternative, which we commonly do want, without needing to add an if |
@mohsen1 @lacker @BrendanFDMoore You can make it as easy as angular if like this, so I don't see any need for an if tag
|
@BrendanFDMoore I'm aware of those workarounds and we're using them. Since JSX is syntax sugar for In your example the syntax can look like this: return (
<div>
<SomeOtherComponent />
<MyInnerComponent *if={isInnerComponentIncludedBool} />
</div>
); I guess mentioning Angular earns you lots of downvotes here! |
@kevinsimper True, it's more compact. We stick to the other convention because instead of @mohsen1 you're right, there's no harm in more helpful sugar to clean up unpleasant syntax where there is wide interest and a commonly accepted pattern. I'm not necessarily against the addition of an |
I find that assigning optional components to variables helps for clarity, for example: function Profile({ user }) {
let avatar;
if (user) {
avatar = <Avatar user={user} />;
}
return (
<div>
...whatever the outer component represents...
{avatar}
</div>
);
} While it would be nice to have direct support in JSX for conditional components, I'm really wary of adding things like |
Automatically bound arrow function that don't allocate a new function everytime:
|
IMHO jsx has only several problems:
JS should have separate context in curly braces. |
With current syntax I think that having multiple ways of doing the same thing adds to overhead when reading the code. It's small but noticeable. |
Make whitespace handling more consistent with HTML: facebook/react#4134 (sorry for brevity, currently mobile...). |
@mohsen1 "It's just JavaScript, not a template language" -> no need to replicate JS functionalities with custom syntax. That is the main benefit of JSX IMO, seriously is so easy to do this with js even if it looks "weird" (for me it is not weird, it is just the syntax of the language) |
I would like to be able to specify some property value with tag : <SplitContainer
left={<div>...</div>}
right={<div>...</div>}
/>
// vs
<SplitContainer>
<.left>
<div>...</div>
</.left>
<.right>
<div>...</div>
</.right>
</SplitContainer> |
@mohsen1 Also with #35 and #39 you could do if (condition) {
VDOM
} wich would be JS instead of some special thing |
Don't fuck it up like Google did with Angular 2, keep the thing compatible with older versions... |
I highly doubt that it makes sense to have full backwards compatibility for JSX 2.0. If we are going to improve it -- we should improve. After all, no one is forced to migrate to JSX 2.0 and you still will be able to write your React apps in JSX 1. React elements/components are just JavaScript calls, so there is no matter what you are using. In some case, if you would like, you probably will be able to use JSX 1 and JSX 2.0 in the same project, e.g. for migration. Just apply new transform for new components. IMO, that's it. |
Though, I'm not a fun of adopting features from Angular. Like some already here proposed are already possible with JSX + React. |
The |
@jeremenichelli For context, this specification is not specific to React. The JSX part already supports |
@sebmarkbage I knew this not directly related to React but thought that the limitation around the use tag was because of JSX and not React itself. Thanks for the response. |
if-else can be written like this: <div>
{ !!something && <Component1 /> }
{ !something && <Component2 /> }
</div> please DON'T implement |
Less features, more |
I'm expressly not in favor of breaking changes... sure, you could support auto-migrations... but there's already a fairly rich set of libraries out there in npm, and if you introduce incompatible changes, how will that work exactly? I mean, adding a few additional features and element support that isn't there now, even supporting "class" as a property directly would be nice... some of the props things, I really don't get...
should work... I wouldn't mind seeing Other pieces can (as I stated above) be done via additional components and existing structures. Keep the changes very minimal and mostly additive imho... |
@lesterzone @tracker1 The things you mentioned above are all part of React. Not the JSX syntax specification that we're discussing here. |
@tracker1 You pull from npm and use in 99.99% cases compiled code, there is no JSX |
return an array of components without a container, like: function List(items) {
return (
<div>
{items.map(item => <Item item={item} />)}
</div>
);
} Turns to: function List(items) {
return items.map(item => <Item item={item} />);
} |
@neiker That has nothing to do with the JSX specification. That's just how React works (one of several uses of JSX). You could propose fragment syntax to JSX 2.0 but that's something else. E.g. return <><Item item={item1} /><Item item={item2} /></>; |
template directive is fucking silly in JSX. Don't mess it up. |
Please don't change JSX. Its now become a popular DSL for html outside of React/Facebook and needs representation from the community and stakeholders. Lots of work has already gone into supporting jsx in editors, libraries and tools like Typescripst's None of the 'improvements' in this thread warrant the havoc/churn in the ecosystem, tl;dr please don't. |
Sam, can you explain why you would be opposed to adding support for HTML/XML-style comments? R. Mark Volkmann
|
@mvolkmann JSX can and should be improved and evolve over time, but the authority to change the JSX specification should be moved to a governance model akin to the tc39 commitee. |
I imagine that would be hard because it is in the middle of XML-ish syntax. On Wed, Nov 9, 2016 at 8:24 AM, Adrian [email protected] wrote:
R. Mark Volkmann |
@jamesseanwright while it is good to understand the reason why "className" is used, I do think that given that jsx is syntactically closer to html than jsx it would be more natural to use "class" rather than "className". Let's keep "className", but let's add support for "class" too. I would then have one less thing to do when I copy-paste static html produced elsewhere in order to transform it into jsx. |
@jpeg729 copy-pasting static html? You use http://magic.reactjs.net/htmltojsx.htm ? :) |
@Adrian1358 sure I could use htmltojsx as you rightly point out, but it seems to me to be an intermediate step that could easily be avoided with a few small changes to jsx. |
As an alternative to becoming more like HTML, what if JSX is more like JavaScript ? For example, it would be nice if we could use template strings without the braces: <input name=`field${index}` /> |
+1 . Please add ability to use |
I wish JSX default args/spread could be extended to behave like a real object. The JSX parser could easily dump args into the _extends function. const localProps = { a: 1, b: 2 }
const opacity = 0.5;
<Component {...this.props, b: 3, ...localProps, opacity, visible: opacity > 0} title="hello" /> Results in React.createElement(Component, _extends({}, this.props, { b: 3 }, localProps, { opacity: opacity }, { visible: opacity > 0 }, { title: "hello" })); Or optimized React.createElement(Component, _extends({}, this.props, { b: 3 }, localProps, { opacity: opacity, visible: opacity > 0, title: "hello" })); |
Revisit: Choosing Type at Runtime In JSX:
But instead:
With CSS in JSX gaining traction, perhaps it is time to revisit? Concerns:
|
What about no |
I'm locking this conversation now. This thread is really too long to read so it's difficult for anyone new to get context on the previous suggestions so we end up repeating old points. Please search the issues or open another issue with new suggestions. |
We have accumulated a number of these nice-to-haves breaking changes that would be nice to incorporate. However, at this point JSX is a hugely adopted syntax in all kinds of tooling. Making breaking changes will churn that ecosystem significantly. I think it is probably only worth doing as a batch when the accumulated amount of changes makes it worth while.
Let's call it JSX 2.0.
What should go into it?
Since a completely incompatible version of JSX has landed in Reason it would be good to find a way to unify them.
I'd say at least we'd want:
Some more controversial/problematic ones that could plausibly be fixed:
What else?
cc @jordwalke @SanderSpies
The text was updated successfully, but these errors were encountered: