Skip to content

JSX 2.0 #65

Open
Open
@sebmarkbage

Description

@sebmarkbage

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

Activity

syranide

syranide commented on Oct 13, 2016

@syranide
Contributor

I would be interested in having a real story for comments e.g. #7. {/**/} feels like a hack, and kind of also is as it affects the children when used in certain places. If we actually end up going with #35 (bold, I like it :)) then just properly supporting regular comment syntax is a no-brainer IMHO.

syranide

syranide commented on Oct 13, 2016

@syranide
Contributor

Also, having an actual syntax for fragments would be a very welcome feature (e.g. the previously talked about <>).

caub

caub commented on Oct 16, 2016

@caub

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 {frag} to insert it.
I think arrays are good enough, similar to DOM fragments, and more powerful to manipulate

comments is a good idea, <!-- --> like html could be fine, but would they be inserted in the DOM (I guess no)? would it conflict with how react uses comments sometimes for text nodes I think

theduke

theduke commented on Oct 16, 2016

@theduke

but would they be inserted in the DOM?

There should be a setting to turn it on for dev / off for production in the implementing libraries.

sbussard

sbussard commented on Oct 16, 2016

@sbussard

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.

mohsen1

mohsen1 commented on Oct 16, 2016

@mohsen1

Something like Angular ng-if would be nice to have in JSX. Making rendering of an element conditional is not easy in JSX. Maybe adopt Angular 2 *if

tachang

tachang commented on Oct 16, 2016

@tachang

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.

jasonslyvia

jasonslyvia commented on Oct 16, 2016

@jasonslyvia

I'd say allow adjacent elements without enclosing tag, really hate additional <div>s like this:

<div>
   <ComponentA />
   <ComponentB />
</div>
syranide

syranide commented on Oct 16, 2016

@syranide
Contributor

@jasonslyvia That's what fragments are for.

alistairhutton

alistairhutton commented on Oct 16, 2016

@alistairhutton

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

oleksandr-shvets

oleksandr-shvets commented on Oct 16, 2016

@oleksandr-shvets
jasonslyvia

jasonslyvia commented on Oct 16, 2016

@jasonslyvia

@syranide It would be better if it could be solved in syntax level.

lacker

lacker commented on Oct 16, 2016

@lacker
<if {myCondition}>
  <div>This part only gets shown if myCondition is true</div>
</if>
BrendanFDMoore

BrendanFDMoore commented on Oct 16, 2016

@BrendanFDMoore

@mohsen1 our convention for our stateless functional components is to use:

import MyInnerComponent from '../my-inner-component';
function MyOuterComponent({ isInnerComponentIncludedBool }) {
  ...
  return (
    <div>
      <SomeOtherComponent />
      {
        isInnerComponentIncludedBool
        ? <MyInnerComponent />
        : null /*Or some fallback component / messaging*/
      }
    </div>
  );
}

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 !someBoolFlag check also.

114 remaining items

adrians5j

adrians5j commented on Nov 9, 2016

@adrians5j

image

Can we add this ? Quick single line commenting :)

mvolkmann

mvolkmann commented on Nov 9, 2016

@mvolkmann

I imagine that would be hard because it is in the middle of XML-ish syntax.
I was hoping it could at least support XML-style comments since this feels
like XML.

On Wed, Nov 9, 2016 at 8:24 AM, Adrian notifications@github.com wrote:

[image: image]
https://cloud.githubusercontent.com/assets/5121148/20141408/84959de2-a690-11e6-9bac-865bb05bb459.png

Can we add this ? :)


You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#65 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAE10DSCR3-4VAbO6_3MdLCZ7vuDrHvdks5q8deZgaJpZM4KVMnP
.

R. Mark Volkmann
Object Computing, Inc.

jpeg729

jpeg729 commented on Nov 19, 2016

@jpeg729

@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.

adrians5j

adrians5j commented on Nov 23, 2016

@adrians5j

@jpeg729 copy-pasting static html? You use http://magic.reactjs.net/htmltojsx.htm ? :)

jpeg729

jpeg729 commented on Nov 23, 2016

@jpeg729

@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.

jokeyrhyme

jokeyrhyme commented on Nov 25, 2016

@jokeyrhyme

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}` />
ghost
drcmda

drcmda commented on Dec 3, 2016

@drcmda

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" }));
gt3

gt3 commented on Dec 13, 2016

@gt3

Revisit: Choosing Type at Runtime

In JSX:

let fns = [() => <p>a</p>, () => <p>b</p>]
<RepeatTwice>{n => <(fns[n]) />}</RepeatTwice>

But instead:

<RepeatTwice>{n => { let F = fns[n]; return <F />; }}</RepeatTwice>

<RepeatTwice>{n => React.createElement((fns[n]))}</RepeatTwice> //OR

With CSS in JSX gaining traction, perhaps it is time to revisit?

Concerns:

  1. Security implications
  2. Component naming convention in React
wqj97

wqj97 commented on Dec 16, 2016

@wqj97

What about annotation
image

neiker

neiker commented on Dec 16, 2016

@neiker

What about no

sebmarkbage

sebmarkbage commented on Dec 16, 2016

@sebmarkbage
ContributorAuthor

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.

locked and limited conversation to collaborators on Dec 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Proposal 2.0Proposals considerable for JSX 2.0

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @nkohari@sophiebits@rauchg@cpojer@fab1an

        Issue actions

          JSX 2.0 · Issue #65 · facebook/jsx