191 points · by tipex · 12y ago · 63 comments
I love React, but so far I've been a bit underwhelmed by the ecosystem of components that has sprung up. I hope that this site will help.
A lot of the components are stuff that aren't really UI elements, but rather add magic to other UI elements or even do something completely unrelated to the UI.
I mean, I've seen routers written as React components![1] Wtf? Why is it an advantage to express a route as XML-like JSX? Why put it in a virtual DOM? That's just waiting for unexpected side-effects to happen. I can imagine that a lean, to-the-point router is a good combination with React but components are for UI widgets, not for configuration.
I feel like this is the same mistake as the everything-in-XML hype of the early 21st century (Spring, anyone?), or the everything-as-a-DSL hype in early Scala (with clear, descriptive operators such as ~~=, $%% and of course &^), or the current hype in C#-o-world to package web assets into NuGet packages (jquery.dll - seriously?). Just because you can put it in a component, doesn't mean that you should.
Behavioral features for components (e.g. infinite-scrolling or tooltip triggers) are well distributed as a mixin. Stuff not directly related to UI widgets should just be vanilla JavaScript. Asset libraries should be asset libraries.
What I expect from open source components is UI elements. Color pickers, fancy dropdown selects, login widgets, form elements with pluggable validation maybe (but the validation logic shouldn't be components). Notably, I'd love an ecosystem of UI frameworks ala Bootstrap or Foundation to spring up around React, and it appears that this is happening.
(Sidenote, if there's one development we do need, then it's a clear React-authors-condoned way to couple (parameterized) CSS with React components, so that we can really distribute self-contained components including style. A development like that would also help focus the React component ecosystem on what it should be about: UI widgets.)
[1] Random example: https://github.com/rackt/react-router#whats-it-look-like - seriously, what were they thinking?
https://github.com/rackt/react-router/blob/master/modules/co...
It doesn't generate any markup itself, but instead renders the component bound to the route. This is a perfectly valid way to communicate how routes are related to components.
I'm assuming the React core team liked the approach as well, considering they featured it in one of their community round-up blog posts:
http://facebook.github.io/react/blog/2014/08/03/community-ro...
You, on the other hand, think it's neat. That's fine.
I don't see how the router's source code is related to this discussion, though. I implied nowhere that that particular router did something bad with rendering markup or something, I'm not sure where you got that from. I'm talking about the API.
The point of JSX is to more easily build dynamic HTML (and perhaps other markup).
It's not really agreeing to disagree when you're openly mocking the idea across multiple paragraphs.
It's not a case of "new hammer", it's being used there for the exact reason JSX was invented - "defining tree structures with attributes" in a standard way since "A generic but well defined syntax enables a community of independent parsers and syntax highlighters to conform to a single specification."
Every application has UI nesting at the core of its state, though.
As for the use of JSX specifically, it's handy because it allows expressing ordered associative data, for which in javascript the other choices are both kind of messy: either an array of objects (verbose) or an object (not guaranteed to be ordered).
This is true as per the ECMAScript spec, but realistically you can count on it (unless your keys are stringified numbers). On the server side of things, this is explicitly depended on in a number of places - the most visible that I know of is Mongo's REPL and its node.js drivers (specifying complex sorting/indexing depends on the objects being ordered).
A better approach (IMHO) is Fluxxor http://fluxxor.com/
And the benefit of the react router is, that you don't have to concern about the render / re-render.
With express you have to do everything by your own.
I think we must difference between Browser - Application Routing and Application - Component - Routing.
I'm not really a front-end person, but when I first saw React it was the first thing I wanted, so I did a bit of work on the idea. A big group of people have now almost finished it.
https://syllog1sm.github.io/react-bootstrap/introduction.htm...
Can't seem to edit my comment...
How do you feel about <script/> tags, or <link/> or <meta/> or <base/>?
Note, I now regret singling out react-router. I'm still learning that on places like HN, it's best to avoid giving examples when discussing software design in abstract terms, because you're needlessly singling out some good people (in this case, you), plus half the discussion becomes a nitpick about the example instead of a discussion about design principles.
I do actually believe that react-router is a bad fit for JSX, let alone React components, but I also think that others are allowed to disagree. The best I can do is try and encourage careful thought when considering JSX, which is what I wrote my comment for, but if people disagree with me on exactly where to draw the line, then that's not really a problem is it?
I hardly have any open source to show for, so you're already way ahead of me, and in the few things I do have on Github, I bet that you'd disagree with some design decisions I made as well.
Sorry for dragging you into this. Open source is unrewarding work and I surely didn't help.
http://gcanti.github.io/resources/tcomb-react-bootstrap/play...
in the next few days I hope to add more constraints. My main concern about react-bootstrap is the massive use of `transferPropsTo`, from what I understand is a deprecated method
This would be pretty useful, especially if it isn't a wrapped version of a well-known existing library.
Solid implementations of autosuggest inputs, token input fields, or fast scrolling tables can run into the thousands of lines. Having reusable versions of them would be very helpful for the React ecosystem.
I have a couple components I can extract from a running project and publish there without any changes (Google Maps, Google Autocomplete, Tagging input, ...) and it will just work.
Want to render a sparkline of some data? Sure, you could mess around with existing libs and see if you can get them to work nice with React, or you could just pull in something you can expect actually works, like react-sparkline.
Here's a jsfiddle for the specific lib you're talking about (Odometer): http://jsfiddle.net/p1h7rn3q/
http://ifandelse.com/using-reactjs-and-kendoui-together/
The JSFiddle example is here: http://jsfiddle.net/ifandelse/U5P32/light/a short description under a package is easier to read.
A structured Category-List will also be helpfull, sometimes i don't know exactly what i search for and then i browse the category (tags).
I think for people building complex applications that have a ton of reusable ui elements react components start to be really enticing because you know you pass this piece of information in and the ui will be consistent throughout assuming there are tests written.
[1] https://github.com/securingsincity/backbone-react-ui - still very much a work in progress
Nice job, looks good!