Coder Social home page Coder Social logo

JSX Spread tag proposal about jsx HOT 5 CLOSED

facebook avatar facebook commented on May 5, 2024
JSX Spread tag proposal

from jsx.

Comments (5)

syranide avatar syranide commented on May 5, 2024

I would say that spreading is not what you want, you want the same behavior as you would get with arrays (if you ignore the key warning) with it being its own hierarchy and implicit indices computed accordingly. A previously discussed syntax is <>, which is also consistent with E4X IIRC (for whatever it's worth).

Also, I imagine if we want to support spreading there's already a solution that wouldn't necessarily introduce new syntax <Parent>{...foobar}</Parent>. Again, not sure why you would want it though as opposed to just fragments.

from jsx.

quassnoi avatar quassnoi commented on May 5, 2024

Don't I have to key the fragments?

Actually come to think of it, <Parent>{...foobar}</Parent> would be nice too. That's what I was naively trying to do in the first place, only to stumble upon an error saying JSXSpreadAttribute being not in the right place. I just failed to find any proposals about this syntax or <>.

Is there any conceptual difference in React between

  • createElement(tag, styles, a, b, c, d)
  • createElement(tag, styles, a, [b, c], d)
  • createElement(tag, styles, a, createFragment({b, c}), d)

?

from jsx.

syranide avatar syranide commented on May 5, 2024

Don't I have to key the fragments?

@quassnoi Using React.createFragment naively requires it yes, it's essentially an associative list (i.e. Map), so everything has to be keyed by necessity. But you could easily feed an array to React.createFragment (use index as key) or have JSX pre-compute the indices and assign keys accordingly.

I just failed to find any proposals about this syntax or <>.

Yeah, I'm not 100% sure TBH. It may just have been "informal/internal" discussions in other places.

Is there any conceptual difference in React between createElement(tag, styles, a, b, c, d) and createElement(tag, styles, a, [b, c], d)?

Yes, a very important one. Removing c in the non-array case would cause React to destroy the instance for d and try to reuse the instance for c but now with the props from d. In the second everything would happen just as you would normally expect.

from jsx.

quassnoi avatar quassnoi commented on May 5, 2024

Are you saying I can just pass an array to createFragment and it will accept it, keying by the index, with no extra effort from the developer's side?

from jsx.

syranide avatar syranide commented on May 5, 2024

@quassnoi Honestly not sure, but you could easily have a wrapper that does it, it's trivial logic.

from jsx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.