Live data from Hacker News

My struggle to learn React

bradfrost.com

61–70 of 218 posts

Re: My struggle to learn React

#61
post #12

This is a fine article. But I just want to say, as an alternate data point, my experience has been exactly the opposite . I love React. React is the first front-end technology I have ever managed to get to stick. * ES6 is just a detail, I know. But for me, ES6 transforms Javascript from an idiosyncratic scripting language where I constantly have to look up the ordinary way to handle basic programming tasks into somet…

Some unsolicited advice from someone who has also been down a similar path.

I normally suggest eschewing the javascript class model in favor of using stateless functional components.[0] I've found them simpler to understand and it cuts down on unnecessary typing. I almost never use 'this' in javascript, and instead have favored an OLOO[1] or pure functional style as it fits into a simpler mental model for how things are working.

I normally only test the actions that modify state in my javascript applications. I care that I'm correctly changing the state of my application, not what that state renders. (This is similar to rails apps not typically testing html output) I normally use mocha[2] for testing and if something goes wrong I can open up a normal chrome js debugger using the --inspect-brk flag when running via the cli.

You will eventually find yourself needing to support multiple routes in your react applications. Most people would recommend the "react-router" library, but I've found a lot more success with "redux-little-router"[3]

[0]: https://reactjs.org/docs/components-and-props.html

[1]: https://github.com/getify/You-Dont-Know-JS/blob/master/this%...

[2]: https://mochajs.org/

[3]: https://github.com/FormidableLabs/redux-little-router

Re: My struggle to learn React

#62
I think I can understand the struggle of the author. I experienced JS as a non-robust / fast-moving programming environment. Frameworks, Buildsystems and Language Features that change every few month. So when I first heard, that React is the new thing and everyone should use it, I did not want to use it. I use React now everyday and I really like it. But instead of writing it with JavaScript I use ClojureScript with a library called reagent(https://reagent-project.github.io/). So changes in JS or React aren't really my problem and CLJS seems to be a reasonably finished language. But I do not want to rate whether it makes sense to trade the weird React syntax for a Lisp.

Re: My struggle to learn React

#63
post #19

Earlier quoted context omitted.

So don't use Redux, React Router, and Thunks. I don't even know what React JSS is. Use create-react-app's tooling. Even Redux's author tells people Redux is overused. A pretty big percentage of the value of the flux pattern is just in having an event pubsub system, so if your application is so complicated that you really feel like you need to structure it, you can just use EventEmitter. I frankly don't understand the…

I mean this in a nice way, I'd really appreciate a gist showing how you get the core concept of react-router in 50 lines. It's in a project of mine now and maybe it shouldn't be.

Here's an article from tyler mcginnis on building your own react router: https://tylermcginnis.com/build-your-own-react-router-v4/

He teaches a good chunk of the react nanodegree course on Udacity and has a lot of good blogs on react.

Re: My struggle to learn React

#64

I don't get what the benefit of using React is, aside from having it on my resume. A virtual DOM? What does that get me? It renders faster? Rendering speed is not a problem my CRUD screens have. Etc., etc. Perhaps some UIs are so complex and dynamic that they're easier to build and maintain using React. I'm not saying other people shouldn't use React, but I'm fairly certain it wouldn't give me enough payback to justi…

The virtual DOM is an implementation detail and is codified as separate packages react and react-dom.

React gets you a consistent UI paradigm (state->ui) that scales well as your app gets more complex or as more members are added to your team.

Re: My struggle to learn React

#66

Earlier quoted context omitted.

I mean this in a nice way, I'd really appreciate a gist showing how you get the core concept of react-router in 50 lines. It's in a project of mine now and maybe it shouldn't be.

Well, it really boils down to const path = findThePath(); class Router extends Component { render() { if (path === "/about") return else if (path.match(someRegex)) { const data = parseSomePath(path); return } else { return } } } Seems as though React Router has gotten a bit complex because it's abstracted away from the concept of a webpage, such that one can use it in the browser, or React Native (which can be a numb…

Just a small addendum to your post -- you shouldn't use react router for react native, you should use react-navigation for that (https://reactnavigation.org/).

Re: My struggle to learn React

#67
post #53

Earlier quoted context omitted.

>React becomes useful when you have really complex and dynamic websites, not when you're building basic CRUD todo applications I realize you're just trying to be dismissive, but in point of fact, my CRUD applications are far more complex than basic todo applications.

You can do a fairly complex system by yourself with a simpler scheme because you have a mental model of how things are organized. It's when you throw more developers into the mix that you run into issues.

>You can do a fairly complex system by yourself with a simpler scheme because you have a mental model of how things are organized. It's when you throw more developers into the mix that you run into issues.

I think that's a fair point. And I think others have remarked that it illustrates Conway's Law.[1] For a front end like Facebook's, that has numerous moving parts, developed by different teams scattered all over the world, and those parts have to fit together and work together in combinations that may not even be foreseeable, then a framework like React may be the only possible way it could be successful.

[1] https://en.wikipedia.org/wiki/Conway%27s_law

Re: My struggle to learn React

#68
I just have to mention Mithril.js (https://mithril.js.org/) here as an alternative to React. It has built-in routing and XHR, and I think it is fairly easy to learn. Combined with the (optional) streams library, it makes developing web UIs extremely pleasant. Like React, it is also based on virtual DOM diffing.

As a very minor point, I think its surface API looks more JavaScriptesque. For example, the life cycle event componentDidMount in React is called oncreate in Mithril.js. Doesn't matter much, but looks better to me.

Re: My struggle to learn React

#69

I don't get what the benefit of using React is, aside from having it on my resume. A virtual DOM? What does that get me? It renders faster? Rendering speed is not a problem my CRUD screens have. Etc., etc. Perhaps some UIs are so complex and dynamic that they're easier to build and maintain using React. I'm not saying other people shouldn't use React, but I'm fairly certain it wouldn't give me enough payback to justi…

Let me add a different point of view. The adoption of React in the world of ClojureScript was pretty much instantaneous and total. I don't think anybody writes ClojureScript webapps in any other way these days. But the way React is used is different: it's used as a smarter mapping from application state to DOM. Clojure and ClojureScript programmers already know how to manage state and limit its spread, React (plus the usually tiny adapter libs) was just a way to efficiently produce DOM renderings of that state.

It fits like a glove. And while it's not all roses, there are fewer friction points it seems than in JavaScript (but then I think JavaScript programmers don't have it easy anyway). Plus, because of the nature of ClojureScript, most articles I read about optimizing React performance do not apply to me, because all the hard work has already been done for me (for example, immutable data structures mean that you can efficiently prevent re-rendering if data hasn't changed).

Anyway, to sum this up with an example that I'm basing my opinion on: PartsBox (https://partsbox.io/) is something I wrote, using React.

Re: My struggle to learn React

#70

re: #5: At my previous job we wrote our own UI toolkit with React and css-modules. We had many dev-only views that we used to inspect and test our components. It worked great because it let you visualize all the states a component could have for a wide range of inputs, so you knew they were all being handled well. For example: If you get a long input prop do any of your styles break from visibility overflowing? If a…

Give React Storybook a look, its tool for easily building component previews for devs.
Post reply on HN