Coder Social home page Coder Social logo

Comments (4)

sophiebits avatar sophiebits commented on May 5, 2024

Your eg2 is already possible in React if you write the If component cleverly.

Your eg4 example would need to change the semantics of JSX pretty drastically because currently every subexpression is eagerly evaluated and there is no way to represent this currently in JSX. I think @jimfb had a proposal somewhere (which we're unlikely to take) but I can't find it now.

from jsx.

danielearwicker avatar danielearwicker commented on May 5, 2024

Yes, @zpao told me how a component could dig down into grandchildren. Sounds scary and wrong!

Regarding eager evaluation, that means I should correct this:

If no attributes are specified, as in eg2, then there is nothing variable for the content to depend on and hence it can just be a simple value rather than a function returning a value.

Instead, my If example should be:

const If = ({test, yes, no}) => test ? yes() : no();

i.e. yes and no are functions, and so eg2 should generate nullary functions, being equivalent to:

const eg1 = (
    <If test={allowed}
        yes={() => <button>Launch missiles</button>}
        no={() => <span>Access denied</span>} 
    />
);

i.e. what I've specified here is purely syntactic sugar, a first-pass transformation based on a pattern that can be found in element names. It would "compile down" to combinations of JSX and {(...) => ... }-bracketed chunks, with behaviour exactly as supported today, as in the above examples.

from jsx.

sophiebits avatar sophiebits commented on May 5, 2024

What you have is already valid syntax though (which means something different than the compilation you suggest). I don't think we're likely to support something like this in JSX itself but you should feel free to make your own syntax extension if you think it's valuable. Thanks for sending the idea!

from jsx.

danielearwicker avatar danielearwicker commented on May 5, 2024

Ah, I see . is already supported and just passed through. : would be a possibility though.

Really I'd like to see this in TypeScript, and it's very unlikely to be adopted there unilaterally.

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.