Hacker News new | ask | show | jobs
by unsoundInput 4164 days ago
I don't think of something as React-like just because it puts HTML and JS in the same file or combines HTML tags with blocks of JS code.

The difference between React and other databinding methods is that you can use all JS language features (i.e. if, for, while, .filter(), .map(), libraries like Rx.js, etc.) when defining what you want your DOM to look like.

Suppose I want to have a list of items based on some array, which I want to filter based on some predicate, and display the items differently based on their content type.

In a React render() function I would just use

  filter( (it) => { //some predicate } ) 
to filter unwanted items, and

  map((it) => { switch (it.contentType) { // cases } }) 
to map the individual items to how I want them to look like.

To me it looks like to implement something like this in Riot would require to build / use something that is more like Angular's computed properties.

But I'd like to be proven wrong.

2 comments

In Riot you need to do following:

<my-tag>

  <div each={ items }>

  </div>

  // use JS to construct items
  this.items = arr.map(fn) // or how you want it
</my-tag>

And you can also manipulate items on every update. I'm sure that at some point there will be a clear use case where React is a better choice.

So far Riot rendering has worked us perfectly.

> I don't think of something as React-like just because it puts HTML and JS in the same file or combines HTML tags with blocks of JS code.

Totally agree. While I do (most of the time) appreciate JSX, it is IMO the least interesting and relevant feature of React. It mostly just lets our company's designers continue to edit view templates that would otherwise be far beyond their training/experience. So that's nice, but it's not what makes React tick.