6 ms·
Nice! I think that if you use vanilla JS (even ES6), the class support adds more hassle than the gains it provides. For example, setting proptypes completely at
by skrebbel 12y ago
Nice! I think that if you use vanilla JS (even ES6), the class support adds more hassle than the gains it provides. For example, setting proptypes completely at the bottom of the file seems, well, cumbersome. It's a bit like putting a function signature after the function body. From that perspective, using the old React.createClass syntax seems to keep everything together a bit nicer.
However, if you want to use e.g. TypeScript with React, than this is a very big thing! Up until now, it was always a bit of a hassle, and with this change, it's completely straightforward (especially if you don't want JSX). You'll also need propTypes less because you can just use TypeScript interfaces for the `props` constructor parameter. Plus, TypeScript already has property initializers and all that, so all the other annoyances that you get when doing this with plain ES6 classes disappear with TypeScript.
I'm currently really considering porting my current project back to TypeScript for this single reason. The bad mix of TypeScript and JSX is what mostly holds me back. I'd like my view code to be somewhat understandable/hackable by designers and JSX really matters there. Any suggestions?
- JonnieCache 12y agoSimilarly, I'm looking for a way to use react with HAML. I just can't give it up, I have absolutely no interest in closing my tags ever again. One of the things I like about angular is how it deals with standard HTML. HAML doesn't care about its wacky attributes. Whats the best way to achieve this with react? Does the JSX compiler have hooks for preprocessing of any kind?
- xtrumanx 12y agoWell JSX is just compiled to JS so I guess you could have something that looks like HAML that substitutes the JSX code which in turn is compiled into JS. Best place to start I guess would be to look into the JSX compiler to see how complicated that would be.
- JonnieCache 12y agoWell if I can get the JSX compiler to give me a hook every time it finds an "html" block, and to let me replace it with my own content, then that would work fine I guess. Then it'd be a matter of getting JSX to recognise haml syntax as html.
- briandear 12y agoI am assuming you could use coffeescript as well?
- pea 12y agoNot what you're looking for exactly, but you could settle for using Jade? https://github.com/duncanbeevers/jade-react https://github.com/duncanbeevers/jade-react
- rapind 12y agoLooks nice. Just a heads up though it uses React.DOM to create your tags which has been deprecated (and possibly won't be available anymore come 0.13).
- sebmarkbage 12y agoReact.DOM is still in 0.13.
- rapind 12y agoThanks, good to know. That gives us a nice path to upgrade our CoffeeScript components.
- rattray 12y agoIt wouldn't work with Typescript, but this is what my vanilla CoffeeScript React code looks like: div className: 'navbar-form' style: backgroundColor: "green" , div className: 'btn-group' , button type: 'button' className: 'btn btn-warning' onClick: @handleDecreaseWpmClick , span className: 'glyphicon glyphicon-chevron-down' span className: 'btn btn-default disabled' , "#{ @props.status.get('wpm') }" span className: 'hidden-xs' , " wpm" button type: 'button' className: 'btn btn-warning' onClick: @handleIncreaseWpmClick , span className: 'glyphicon glyphicon-chevron-up' (For the curious, "wpm" is short for "words per minute" - this is straight out of my code for http://splashreaderapp.com http://splashreaderapp.com. More code at http://github.com/rattrayalex/splashreaderapp http://github.com/rattrayalex/splashreaderapp)
- rapind 12y agoPretty sure you can lose all of those single line "," and make it a bit nicer. div className: 'navbar-form' style: backgroundColor: "green" div className: 'btn-group' button type: 'button' className: 'btn btn-warning' onClick: @handleDecreaseWpmClick span className: 'glyphicon glyphicon-chevron-down' span className: 'btn btn-default disabled' "#{ @props.status.get('wpm') }" span className: 'hidden-xs' " wpm" button type: 'button' className: 'btn btn-warning' onClick: @handleIncreaseWpmClick span className: 'glyphicon glyphicon-chevron-up'
- funksta 12y agoIt's not quite the same as HAML, but you might try JSnoX: https://github.com/af/JSnoX https://github.com/af/JSnoX
- colin_jack 12y agoMaybe off topic but I've been wondering whether many people are finding spending time on TS worthwhile? Given the improvements in ES6, the fact that the JS community in general is so active, and the fact that I've seen some truly awful TS code (mainly where the devs want to pretend the web doesn't exist) I've been put off exploring TS too far much (beyond looking at the basic language features). I'm not sure if I should be rethinking though?
- wereHamster 12y agoThe 'Type' in TypeScript.
- colin_jack 12y ago?
- jnbiche 12y ago> seen some truly awful TS code (mainly where the devs want to pretend the web doesn't exist) I agree. Typescript is an impressive project, but most of the Typescript code I see looks more like C# or Java than Javascript. Sadly, it seems to have been created to accommodate that kind of approach. But there's a lot to be said for strong and static typing when dealing with large projects. That's why I'm hopeful for Flow, Facebook's new project to add static typing to Javascript: https://github.com/facebook/flow https://github.com/facebook/flow
- colin_jack 12y agoYeah the stuff I've seen looks to me like poorly written C# consciously written in a Web-ignorant style, thoroughly at odds with whats going on in the Web/JS community generally. Anyway totally agree on the typing angle, navigation/refactoring/discover-ability aspects are useful and I loved the implicit interface approach in Dart. However I wonder whether some of those features won't be added to JS over time (where possible in such a dynamic language). Ta for link to flow, will give it a look thanks.
- rpwverheij 12y agoI'm using Typescript + React for quite a big project, and I'm really happy with it (and even more happy with how things will work soon with this release). True, not being able to use JSX is a really big minus. Personally I'm fine with the js style "HTML.div({properties},children)" for now, and there are some people trying to get TS + JSX to work, (see https://github.com/ripieno/typescript-react-jsx https://github.com/ripieno/typescript-react-jsx and https://github.com/fdecampredon/jsx-typescript https://github.com/fdecampredon/jsx-typescript) havn't tried it myself yet, but I have good hopes this will work properly some time soon
- jbrantly 12y agoMy talk at React.js Conf is on exactly this topic: how to integrate React and TypeScript. For JSX the approach I recommend is a bit of a hack but works quite well. You basically tag the JSX in such a way that the IDE is happy. Then in a precompile step you find, transform, and replace the JSX[1] prior to passing to TypeScript for final compilation. You lose out on intellisense and autocompletion but you still get type-checking and can still use some ES6 features in your JSX like fat arrows. 1. https://github.com/jbrantly/ts-jsx-loader https://github.com/jbrantly/ts-jsx-loader (for webpack, but basic approach works in gulp/grunt as well)