GithubHelp home page GithubHelp logo

Comments (11)

tomitrescak avatar tomitrescak commented on May 31, 2024 4

I am using this successfully with Babel 7 (example repo https://github.com/strothj/react-app-rewire-typescript-babel-preset).
Here is the .d.ts file

declare var If: React.SFC<{ condition: boolean }>;
declare var For: React.SFC<{ each: string; index: string; of: Array }>;
declare var Choose: React.SFC;
declare var When: React.SFC<{ condition: boolean }>;
declare var Otherwise: React.SFC;

from jsx-control-statements.

avityaz avatar avityaz commented on May 31, 2024 2

For TS you can use ts-control-statements

from jsx-control-statements.

KonstantinSimeonov avatar KonstantinSimeonov commented on May 31, 2024 1

I've rolled this that provides the same syntax, but for the typescript compiler.

from jsx-control-statements.

AlexGilleran avatar AlexGilleran commented on May 31, 2024 1

Added to readme 😎

from jsx-control-statements.

texttechne avatar texttechne commented on May 31, 2024

Since this plugin is a Babel plugin you defintely need to use Babel. You have two options:

  1. Mature but complex: Use Babel for transpiling JSX code and typescript for transpiling everything else
  2. Beta but promising: Use Babel7 with TS support

No examples, but maybe a pointer in the right direction?

from jsx-control-statements.

danielkcz avatar danielkcz commented on May 31, 2024

What a shame. I was kinda excited to find this lib expecting it's just set of components that would make my life easier. I am using TypeScript too and I certainly don't want to add Babel into the mix just because of this.

I am not expecting to get a babel free variant here. I am more of curious why this actually need to be a Babel plugin? I mean is there really that much of performance gain by transpiling this?

from jsx-control-statements.

AlexGilleran avatar AlexGilleran commented on May 31, 2024

The babel plugin isn't actually for performance, it's because the interior of a React component gets executed even if it's not rendered: https://github.com/AlexGilleran/jsx-control-statements/wiki/Why-Transform.

I've been thinking you could do a lot of this with render props at the cost of slightly uglier syntax, but haven't gotten around to it :(.

from jsx-control-statements.

danielkcz avatar danielkcz commented on May 31, 2024

I see now, thanks for the explanation. Haven't really thought about this issue before, it's kinda eye opener :) That link to the wiki should probably be in readme, not many people will check wiki imo.

I was kinda thinking about using this more for a boolean value checks then for existence checks, but I can get away by making my own component for that. Doing this with render props would not probably make sense, it would get too bloated. Personally I have a limit of 2 render prop component in a single jsx tree.

It's a pity that TypeScript plugin system cannot really do what Babel can. It's not possible to extend syntax in any way. Well, perhaps it's a good thing also as it keeps the code consistent without surprises.

from jsx-control-statements.

AlexGilleran avatar AlexGilleran commented on May 31, 2024

whoa! rad!

image

from jsx-control-statements.

KonstantinSimeonov avatar KonstantinSimeonov commented on May 31, 2024

gif

from jsx-control-statements.

tomitrescak avatar tomitrescak commented on May 31, 2024

@AlexGilleran would you consider adding the tsx syntac to the for statement?

<For of={names} body={(name, i) => (
        <li key={name}>
            {i}<string>{name}</strong>
        </li>
    )} />

The work of @KonstantinSimeonov is pretty amazing, but it does not allow to be used with babel-loader which effectively makes things complicated around CRA.

from jsx-control-statements.

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.