5 ms·
I stopped using JSX with React+CoffeeScript. I think the following looks a lot cleaner and removes the jsx dependency: {div, a} = React.DOM ... re
by dugmartin 11y ago
I stopped using JSX with React+CoffeeScript. I think the following looks a lot cleaner and removes the jsx dependency:
{div, a} = React.DOM
...
render: ->
(div {},
(a {href: 'foo'}, 'bar')
)
The only downside is having to extract the tags from React.DOM.
- mikewhy 11y agoWouldn't you have to use `React.createFactory` in this case as well? (when not dealing with React.DOM components)
- dugmartin 11y agoYes you do need to use it. I put each component in its own file and use Browserify to require them in like this: MyComponent = React.createFactory require './my-component' then you can do render: -> (div {}, (MyComponent {}) )
- seivan 11y agoYou could omit the parenthesis and it starts to look a lot like HAML :-)
- dugmartin 11y agoThe parens help to make sure CoffeeScript parses it correctly. Plus it looks kind of Lispy which is good right?
- seivan 11y ago"looks kind of Lispy which is good right?" :D, you sound not sure :) I haven't had any issues without the parens, but then again I've only just fooled around. You probably know better.
- Keats 11y agoWorks very well in typescript as well !