News for hackers. Stuff that matters.
Re:What I wish I knew about React by dvcrn on Wednesday April 29, 2020 @03:44AM (#23016510)
I am not so up to date with frontend dev but what's with the hate towards React these days? It still does what it's supposed to do very well and very fast. Yeah sure if you want JSX you need transpilation but I would want that anyway if I want any of the ES6 features without losing browser compatibility.

And it's also constantly evolving and getting better. Just recently I started a React project with class components only to learn that hooks are now a thing and they remove a lot of boilerplate code. Even with redux, redux supports hooks as well so you can scrap that entire connect() stuff alltogether. Just back to simple function components.

Re:What I wish I knew about React by ggregoire on Wednesday April 29, 2020 @03:55AM (#23016584)
> I am not so up to date with frontend dev but what's with the hate towards React these days?

HN is rarely the place to read constructive comments about JavaScript and frontend development.

Personally I've been developing web apps for 10 years (with technologies such as Spring, ASP.NET, CakePHP, Symfony, Django, jQuery, Backbone.js, Angular 1) and I quite enjoy React. I think it makes my job easier and I feel productive with it.

Also, TypeScript is awesome.

Re:What I wish I knew about React by chadcmulligan on Wednesday April 29, 2020 @05:11AM (#23017053)
Its reaching the point where it is becoming standardised, and therefore not interesting, and so it must pass, and a new framework will become the one to use for web development. It's axiomatic that web development must be cool and new and therefore no framework can ever become a standard.
Re:What I wish I knew about React by sjwright on Wednesday April 29, 2020 @11:13AM (#23020194)
I still write web in ColdFusion and (mostly) plain JavaScript. Seriously. I’m not cool at all.
Re:What I wish I knew about React by jaeyson on Thursday April 30, 2020 @06:17AM (#23029305)
I'd still say cool tho.
Re:What I wish I knew about React by karolsputo on Thursday April 30, 2020 @05:56AM (#23029186)
I see a lot of pro-Svelte comments/entries on HN. It seems to be endorsed stronger than the mainstream, big libraries right now
Re:What I wish I knew about React by mercer on Thursday April 30, 2020 @09:09AM (#23030385)
My impression is that for a lot of developers on HN, a kind of front-end fatigue has grown stronger and stronger. And as a result, there's a preference for various solutions that reduce the amount of 'dynamic javascript' work required.

While I'm not particularly hostile to javascript or React myself, I do notice that over time, I tend to avoid it whenever I can. It wasn't too long ago that I made (gentle) fun of Intercooler.js (what happened to that person and their tireless efforts to insert it into any vaguely relevant conversation?), for example.

But nowadays, I'm fully on the Phoenix LiveView bandwagon (React/js on the server!), and I would absolutely use Svelte or Intercooler if LiveView wasn't an option, I grumble whenever I need to deal with my js pipeline (Webpack, PostCSS, etc.), and whenever I do need to deal with it, I get an almost existential 'where did things go wrong' feeling. Maybe I'm just getting old, in front-end developer terms anyways.

All I know is that for the past year I've barely kept up to date on the latest in React (Hooks?!), CSS (grids? flexbox?), js bundlers, browser features (webworkers? the latest in LocalStorage? webcomponents?), and so on, and instead I've been dealing with databases, servers (nginx, linux, etc.), and other 'back-end' things instead.

I feel much, much less frustration because suddenly things stop working and I need to dive into the complex world of webpack and its loaders, CSS and it's various browser incompatibilities, and so on. But I also feel that the things I /do/ learn will probably be valuable for years to come.

The insane amount of stuff I've learned about jQuery is practically worthless now. The same goes for Bootstrap and Backbone.js. Or various CSS layout tricks (dear god the floats). But what I'm learning about Postgres and Ngix and Railsy back-ends seems like the kind of stuff I'll be able to use (and make a living off) for a long time to come.

I do really like TypeScript though. I'd love to use that more :).

Re:What I wish I knew about React by dandigangi on Wednesday April 29, 2020 @11:16AM (#23020237)
> HN is rarely the place to read constructive comments about JavaScript and frontend development.

So, so true. Not even just JS though. Community can be rough on people generally.

Re:What I wish I knew about React by kreetx on Wednesday April 29, 2020 @04:01AM (#23016632)
What's a good place for front-end dev discussions, especially the type which are more on the meta-level?
Re:What I wish I knew about React by m5r on Wednesday April 29, 2020 @09:28AM (#23018844)
Twitter can be a good place sometimes

/r/webdev, /r/javascript and /r/reactjs too

Re:What I wish I knew about React by fit2rule on Wednesday April 29, 2020 @05:10AM (#23017051)
http://lobste.rs is a good starting point. Not as much hate there..
Re:What I wish I knew about React by wtmt on Wednesday April 29, 2020 @01:51PM (#23022061)
Related question: Does it still require hanging around and waiting for an invite to create an account? If yes, then I’m not going to try again and waste my time.
Re:What I wish I knew about React by fit2rule on Thursday April 30, 2020 @04:08AM (#23028603)
Its not hard to get an invite. I'd invite you if I knew your address.

I consider this a slight inconvenience but still a better system than having the dang hammer around to pound spammers ..

Re:What I wish I knew about React by tenaciousDaniel on Wednesday April 29, 2020 @09:35AM (#23018904)
I've been considering the jump into TS, but I don't want to end up in a coffeescript situation (i.e. language is dead, but code lingers on and has to be converted back to JS at some point, rather painfully). Do you think it's worth it?
Re:What I wish I knew about React by slewis on Wednesday April 29, 2020 @10:21AM (#23019563)
Yes. It’s built by Microsoft and has huge adoption. Typescript is here to stay.
Re:What I wish I knew about React by akie on Wednesday April 29, 2020 @12:11PM (#23020862)
What if most of TypeScript is embedded into the next version of JavaScript, as happened with Coffeescript?
Re:What I wish I knew about React by zdragnar on Wednesday April 29, 2020 @12:41PM (#23021174)
Typescript offers almost no runtime behavior. With a few exceptions, everything is stripped out, and it only offers to transpile modern JS features to older browsers. CoffeeScript was all about an alternate syntax for runtime behavior.

JS isn't going to get compile time anything. There was an attempt at adding "strong mode" by one of the google / chrome teams iirc and that went nowhere.

Re:What I wish I knew about React by Zarel on Wednesday April 29, 2020 @01:33PM (#23021852)
All I really wanted was to allow type annotations in JavaScript. So you wouldn't need a compile step while running (JavaScript would just ignore the type signatures), but TypeScript could check it whenever. I believe this is the approach Python uses.

I think there were discussions of doing that at some point, but it seems to have gone nowhere.

Re:What I wish I knew about React by StrangeSound on Wednesday April 29, 2020 @12:28PM (#23021036)
Then there's not really a problem. You learned how it works, and now it's one less thing to worry about
Re:What I wish I knew about React by hombre_fatal on Wednesday April 29, 2020 @12:42PM (#23021199)
Also, if Javascript got its own type system somehow (not gonna happen anytime soon), you could expect Typescript to compile to it.

And you could transition off of Typescript just as gradually as you could transition on to it.

Re:What I wish I knew about React by JackMorgan on Wednesday April 29, 2020 @10:35AM (#23019732)
I just switched a pretty huge project into TS, and I'm seeing for this team and project, probably 4 units of saved time in the PRO column, and 3 units of lost time in the CON column. Still worth it, but you'll need to learn and maintain a new thing, and sometimes doing a totally normal JavaScript thing would force you to write some pretty eldrich type signatures.
Re:What I wish I knew about React by fpoling on Wednesday April 29, 2020 @12:04PM (#23020785)
You may also consider Flow. It is literally JavaScript plus type annotations. The annotations can be even put into comments turning the files into vanilla JS making this very clear. So there is no danger that if FB abandons it one ends up with code that needs to be converted.

On the other hand Flow is much less cool than TypeScript these days. Plus using it for development under Windows have issues, although FB has started paying attention to them.

Re:What I wish I knew about React by Zarel on Wednesday April 29, 2020 @01:30PM (#23021822)
TypeScript annotations can also be put into comments. I like TypeScript's approach (JSDoc) better, actually, because it's how you'd want to annotate them even if you didn't have a typechecker, anyway.

Although I still hit enough annoyances that I'd go straight to `.ts` files for my next project.

Re:What I wish I knew about React by FeloniousHam on Thursday April 30, 2020 @11:15AM (#23031731)
We started out with Flow, but moved to Typescript not because it's "cool" (I suspect it's the Flow users who are smoking clove cigarettes in black berets), but because the language improvements and tooling support are a huge productivity boost. The killer is how flexible it is, it incrementally scales from straight JS to full-on type religion. You only have to use as much as you find useful.
Re:What I wish I knew about React by TechBro8615 on Wednesday April 29, 2020 @03:35PM (#23023215)
If you decide to make the jump, I found tsdx to be really useful boilerplate generator for getting started: https://github.com/jaredpalmer/tsdx
Re:What I wish I knew about React by mercer on Thursday April 30, 2020 @09:15AM (#23030436)
I've been doing less and less JS stuff, but I actually miss TS at times. I think it won't end up like CoffeeScript, and it's absolutely worth using if you need to write javascript!
Re:What I wish I knew about React by carry_bit on Wednesday April 29, 2020 @10:54AM (#23020002)
Unlike coffeescript which had a fundamentally different syntax, typescript is just modern javascript plus types.
Re:What I wish I knew about React by davnicwil on Wednesday April 29, 2020 @11:49AM (#23020613)
I agree and won't repeat this point in a sibling comment, but just a slight nuance is that there are in fact some extra features/syntax TS has that JS doesn't, such as enums.

You have to be aware these features would need to be manually converted back to JS were you ever to switch back. Honestly this would likely not be a significant amount of work, especially if you don't overuse them, but just to make you (GP) aware.

Re:What I wish I knew about React by azangru on Wednesday April 29, 2020 @07:21AM (#23017881)
I love React and write it, in Typescript, on a daily basis. However:

- It starts you off with about 40kB of minified gzipped javascript; some developers feel that it's too much.

- It is not and probably never will be the most performant framework out there, which upsets quite a few people (although the work that the React core team is doing with Concurrent Mode probably means that from the end user's perspective React will feel fast enough).

- It has become the default way for many frontend developers to write JavaScript; I know I am personally guilty of that. This generates a lot of resentment from more experienced developers who have learned to prioritise minimalistic JavaScript bundles over developer experience.

Re:What I wish I knew about React by II-V-I on Wednesday April 29, 2020 @08:06AM (#23018131)
Your last point is a cause of some apprehension for me. In the team I'm currently working with one of my coworkers calls himself a React Developer, and my experience has been that anytime an issue arises that may not be specific to React, this person's ability to problem solve significantly diminishes.

I've seen it in a couple of other individuals as well, and I feel it's becoming more widespread, though I hope I'm wrong. In these instances, I see the framework existing both in the code as well as the mind, and operating outside of it is often a leap too far.

Re:What I wish I knew about React by sngz on Wednesday April 29, 2020 @02:09PM (#23022267)
> and my experience has been that anytime an issue arises that may not be specific to React, this person's ability to problem solve significantly diminishes.

this has been my experience too, I'm a full stack engineer playing a devops role right now on a greenfield govt project. Getting our CI/CD pipeline going within our environment constraints with react has been a pain in the ass. Every time something goes wrong the front end dev just kinda throws his hands up and basically tells me its my problem. I ended up having to go through all the issues opened on github to find solutions and implement them myself. I'm no javascript expert but to me the solutions seem to be super hacky when I've found other frameworks out there that handle these things out the box or more gracefully.

I was on a project supporting legacy code for a long time before this, and was quite looking forward to working with newer js frameworks but this left a sour taste in my mouth. And I already had a bad impression of react prior. I might look into pushing for some of the alternate frameworks out there.

Re:What I wish I knew about React by II-V-I on Wednesday April 29, 2020 @04:58PM (#23024207)
Oof. Sorry to hear the FE dev gives up like that. You may become a JS expert if that carries on.

> the solutions seem to be super hacky when I've found other frameworks out there that handle these things out the box or more gracefully.

I'm curious to hear what alternative frameworks handled these things better? The only one I've used recently, other than React, is Vue.

Re:What I wish I knew about React by sngz on Wednesday April 29, 2020 @06:02PM (#23024955)
So the issue I'm referring to is this, which has been open since 2017 https://github.com/facebook/create-react-app/issues/2353

There's a slew of workarounds offered in that github issue, most people (including another team in my org) opted to just rebuild the app every time a docker container is created which kind of defeats one of the major pros of using docker IMO.

I ultimately ended up forking off this repository and customizing it to my needs https://github.com/beam-australia/react-env

that solution in itself is very hacky.

as far as I know, vue doesn't have this feature either but I think next.js and nuxt.js does.

Re:What I wish I knew about React by azangru on Wednesday April 29, 2020 @09:07PM (#23026439)
> So the issue I'm referring to is this, which has been open since 2017

I probably don't appreciate the complexity of the issue, but I would say environment variables are not React's concern; it’s up to you how to architect your code. If you want runtime environment variables, then either add them to the html that React will render into, so that the javascript code can read these variables in before rendering, or have an api endpoint that your app will query before or during rendering and will get all the relevant config information from it.

> but I think next.js and nuxt.js does

Probably because they server-side-render. And even if your app renders on the client side; even if you don't use next, nuxt or whatever, there is no-one stopping you from dynamically serving the html skeleton with the relevant variables in it.

But then, it all probably has been mentioned in that issue. I wonder why it wouldn't be a good solution.

Re:What I wish I knew about React by sngz on Thursday April 30, 2020 @12:14AM (#23027362)
> but I would say environment variables are not React's concern; it’s up to you how to architect your code

I don't consider it part of the "code" but part of configuring the application based on the environment you're deploying it on(Precisely why the FE dev basically said its not his problem). The fact that a lot of people are suggesting you just build the app every time you deploy a docker container is really concerning to me.

> I wonder why it wouldn't be a good solution.

it just feels dirty. it's the fact that I have to add these into the code that it feels like a hacky solution for a production app. using a shell script to read read the OS environment variables to create an ENV file then convert that ENV file to a javascript file that is then read, it seems like many things can potentially go wrong.

Ideally they would just deal with this within the dotnev library

Re:What I wish I knew about React by azangru on Thursday April 30, 2020 @05:09AM (#23028925)
Dotenv runs on the server. If a part of your application also runs on the server (such as with Next, Nuxt, etc.), and your responses are generated dynamically, then it is trivial to use the dotenv. If, however, the runtime of your application is confined entirely to the browser, and what you are serving to the browser is only static assets, such as with create-react-app, then, if you still want your environment variables to be defined at runtime rather than at build time, you need to design a bridge between your server and your client specifically for injecting the environment variables.

Here, for example, is an article describing such an injection at the nginx level: https://medium.com/@jans.tuomi/how-to-use-environment-variab.... Or you can serve index.html using a full-fledged dynamic server, such as Node, and inject environment variables there (and probably cache the response for good measure as well, not to overstrain Node). This really is not something that is React’s responsibility — although it may very well be the responsibility of the frontend developer to set this all up.

Re:What I wish I knew about React by sngz on Thursday April 30, 2020 @01:25PM (#23033427)
yep i know how it works after looking into it since I didn't know anything about react before, just makes me not want to use react or vue for any enterprise level software.

All those solutions you mentioned I've considered and are mentioned in the github issue. I just think its way too much work and overly complicated for what is basically a prototype. Which is why I opted for the simple hacky solution.

> This really is not something that is React’s responsibility

This is why I'm already pushing for our team to move off react I don't think its the right fit for us. We also don't like JSX

Re:What I wish I knew about React by JackMorgan on Wednesday April 29, 2020 @10:39AM (#23019796)
Personally, I'm super wary of any ____ developer. It's a fixed (vs growth) mindset that tells me they are specialists. I think specialists are best to be consulted by generalists, but not trusted with larger decisions outside their scope.
Re:What I wish I knew about React by dehrmann on Wednesday April 29, 2020 @12:32PM (#23021080)
This is usually a smell that the person is competent at what they do, but doesn't know what's going on under the hood. Funny enough, I'd rather work with someone who doesn't know the specific technology, but knows what the language was built on top of, because they'll have a better intuition for how it actually works and be able to learn it relatively quickly.
Re:What I wish I knew about React by II-V-I on Wednesday April 29, 2020 @04:49PM (#23024121)
I'd rather work with someone like that, too. All is well and good when one can crank out React components, but if that same person doesn't know how to find, for example, the tag name of a element from an event handler, a little red flag goes up for me, and as you said, probably doesn't know a great deal about what's going on under the hood.
Re:What I wish I knew about React by otachack on Wednesday April 29, 2020 @11:33AM (#23020433)
Maybe bring it up to him with constructive criticism? Tell him the wind tends to change direction and one shouldn't typecast themselves in this field.
Re:What I wish I knew about React by II-V-I on Wednesday April 29, 2020 @04:40PM (#23024003)
I agree. Though this person can be a bit touchy when constructive criticism is aimed at them, this would most likely be beneficial for them, and also the team, in the medium/long run.
Re:What I wish I knew about React by jchw on Wednesday April 29, 2020 @03:49AM (#23016540)
It’s the price of success. Similarly, a lot of people now vehemently hate Go, and in a few years they’ll be complaining about the problems with Rust. (No idea about frontend because as far as I’m concerned React is still on top.)

I don’t think it’s really too big of a deal, but I wish people would be more realistic and use less hyperbole. Everything has trade-offs, one’s own personal honey moon ending does not mean we were all blind and/or ignoring the faults with things.

Re:What I wish I knew about React by saagarjha on Wednesday April 29, 2020 @04:59AM (#23016991)
I don’t think it’s necessarily success, but novelty. C++ and Java are immensely popular and get nowhere near the vitriol that the thing you mentioned do. Often there’s a number of people on the opposite side cheerleading the thing as well, which underlines the apparent conflict. (Rust is already being complained about, by the way.)
Re:What I wish I knew about React by christophilus on Wednesday April 29, 2020 @05:38AM (#23017231)
Really? I would have put C++ and Java near the top of the “most ridiculed languages” list.
Re:What I wish I knew about React by majewsky on Wednesday April 29, 2020 @08:37AM (#23018336)
As the old mantra goes, "there are two types of languages, the ones that everyone complains about, and the ones that nobody uses".
Re:What I wish I knew about React by shrimp_emoji on Wednesday April 29, 2020 @12:02PM (#23020771)
That's true because the more first-mover-y languages that came to dominate are shit compared to subsequent, more innovative ones.

When the latter become dominant, there should be even more subsequent, innovative ones.

And the cycle will repeat.

But it's less net shittiness with every generation. And how many generations are we even in so far? C is '70s security gore, C++ is an '80s attempt to force OO memes that we've come to regret onto the '70s security gore, Python and Java are '90s OO memes in earnest, JavaScript and PHP were kludgy mistakes slapped together in a fit of desperate confusion to get some web shit to run, aaand...

Re:What I wish I knew about React by neutronicus on Wednesday April 29, 2020 @09:24AM (#23018801)
As a C++ developer who occasionally helps a friend hack on a Rust hobby project, I've been waiting for the other shoe to drop on Rust.

Not necessarily because I have many complaints about it, but because I consider it in essence very similar to C++17, with (not-too-)different syntax and a few different but important design decisions in the core language and standard library. Seeing it sold as a radical paradigm shift from C++ has always left me feeling that some people are in for disappointment down the line.

Re:What I wish I knew about React by fpoling on Wednesday April 29, 2020 @12:19PM (#23020942)
C++ has no notion of a borrow checker and I am not aware of static checkers for the language that provides a coverage close to that of the Rust compiler.

As I continue to see how very experienced C++ programmers make exploitable bugs that passes all reviews and that are compilation errors in Rust saying that Rust is C++ with a different syntax is very naive.

Re:What I wish I knew about React by tannhaeuser on Wednesday April 29, 2020 @08:08AM (#23018145)
Because it's overhyped to the point it's being used everywhere even for projects where there was no reason to ever go beyond basic static HTML + maybe vanilla js, if at all, by devs who want to pad their resume. At the same time, it taxes your mobile battery, and generally leads to a world of overcomplicated appified Chrome-only web sites when actually the web was meant as a straightforward mechanism for self-publishing and exchanging ideas. Finally, reading the umptieth take of a junior dev having his React epiphany, or worse, a staged React consultancy/course ad piece provokes counter-reaction, if only because it's intellectually insulting.
Re:What I wish I knew about React by sametmax on Wednesday April 29, 2020 @06:07AM (#23017423)
I've been coding and training people in react for a while now, and here is my experience:

- if you learned react by yourself years ago, you had to go through a lot of pain: the doc was terrible, the ecosystem a moving flaky target and conventions were not established. Things are better today, but it's not something you forget. Somebody starting react in 2018, and with create-react-app, will feel much happier.

- if you come from projects were you sparkled JS a bit, and suddenly you move to SPA with react, which is the experience of many, it feels like a wall. In fact, for many, React is the gateway to JS, and it pays the price for it: if you dislike working with JS (which is not uncommon if you come from another language like Ruby, Python, etc), you associate it with React. If you don't do JS full time and suddently must embrace the full stack of it just to make a UI, it's overwhelming. And despite the message you can use bare bone react, nobody does that: you use react, you eat the burger tower with it. Webpack reputation espacially, tainted react reputation.

- react has been oversold and overhyped. It doesn't help that the react community has been in deny of all its problems for years. They fixed many eventually, but before they did, they claimed it was all wonderful. It felt insulting for some people, espacially senior devs from other techs who knew the youngsters in front of them were full of it.

- the whole store concept has been a debacle. First there was a mysterious name (it's a plane, it's a train, it's flux!), but no solution. Then there were too many. Then Redux won. But Redux is so full of boilerplate. But wait, "you don't need Redux". But then people hacked many solutions internally to avoid redux with no guidance. Then redux toolkit and react provider arrived. In general, react and its ecosystem changed too fast. Way too fast. Unless it's your full time job, it's very hard to keep up. If all techs did that, we'll never be working. Combine that with the JS community desire to always use the latest toy, and you get a rat race. People have work to do, they don't want to deal with drama. React ecosystem is a drama queen.

- there is no convention on how to write a react project. Everytime you move to a project, it's a new project. You relearn the layout, the naming convention, the way store is handled, how things are passed around, the libs used for basic things, the testing infra, glue code for said libs, how you deal with css, the granularity of components, API best practices, etc. Not to mention the flavor you are in, depending of the version of react used and the fashion at the time. That's just for react. Then you deal with the other JS techs.

- so now, how do you know what to do? Who to trust? Where to get the gospel from? Thousand of tutorials, many imcomplete, obsolete, unpractical, specialized or dishonest. Just the way to manipulate something as simple as props have so many variants with different implications, and you got them all online. All. Of. Them. If you come from the ordered and well established world of backend frameworks, it's a mad house.

- then there are the gotachas. setState() is asynchronous, auto bind on createClass, but not on extends (but yes if render()). There you gotta call super(props), not here, useEffect dependancy management... React is full of them.

- when the magic doesn't get you, it lets you down. Some basic operations, like settings classes, preventDefault, communicating with the parent, etc. that you do all the time, are incredibly verbose for no good reason ("it's just JS you all!). Most other libs have shortcuts for them. In fact, most react projects add libs to get on par. When I train people in react and they ask me how to do this simple thing, I get desperate looks: "really?".

- integrating react with legacy frameworks like RoR, Symphony or Django is really, really not fun if you don't have a SPA with an REST API. And everybody does it differently.

- react native code reuse was a lie. A damn lie. And its great perfs as well. Nobody likes to be lied to.

- the immutability story is the last straw. I get the benefit of it. But for the vast majority of projects I met in the wild, the cost is way to high. This has so many ramifications I would need another comment just for this one.

Bottom line, if you work with seasonned programmers like it's often heard on HN, you can make the best of react. If you don't, and I work a lot with schools, administrations, average corporate IT deps, etc., the cost of react is going to weight on the team.

The teams that can manage React correctly are not that many outside of our bubble.

And for the ones that can, the price of using react may just be not worth it.

When I give the same exercice to do with Vue and React, beginners doing Vue finish in half the time. So I usually advice for Vue. Life is short, and you are probably not facebook at scale.

Re:What I wish I knew about React by derryrover on Wednesday April 29, 2020 @12:56PM (#23021391)
Best summary of the state of react I have read so far after programming with it for 2 years. You should write an article about it!

Stuff like this is rarely part of the sales pitch for any framework. You only find out after being locked in neck deep. Still from all the browser gui frameworks I think react is the safest choice.

Why? Well it is reliable and scalable enough and create-react-app makes the whole experience acceptable. It will not get you into trouble. Choosing any of its non-mainstream competitors might get you into deep shit if the project fails. Choosing any of its mainstream competitors like Vue or Angular seems like not a big improvement over react (if it even is) and will make you go into defensive mode anytime a junior dev knows that feature x would have been easier to implement in react.

Re:What I wish I knew about React by partyboat1586 on Wednesday April 29, 2020 @07:23AM (#23017890)
React native code re-use is possible just not in the way people imagined. You can reuse your Redux code, you can reuse higher order components you just can't reuse the atomic UI elements.

React native performance is good too it just doesn't come for free. You need to know how to do native animations and you need to do late binding and all the other performance optimisations you should be doing with React anyway.

The only thing that lets React Native down is the tooling. I've had the debugger repeatedly push stale code on refreshes, the source mapping is atrocious and sometimes the network debugger just refuses to work. Also sometimes the app fails to load and you need to reload the app and or restart the debugger and or restart the packager in the right order.

Re:What I wish I knew about React by iainmerrick on Wednesday April 29, 2020 @09:07AM (#23018628)
Is React Native performance really good? Compared to what?

I've found RN performance passable but underwhelming. It seems generally worse than a good native UI, and no better than a mobile web UI.

I don't understand why the JS is run in a separate thread, rather than just using the UI thread for UI (as it's intended for). By making all the interaction with the native toolkit asynchronous, it adds extra latency and leads to unavoidable glitches in native widgets used as controlled components.

Animation in React Native is much more of a hassle than UIKit or even CSS. (About the same as native Android, though, where it's also pretty tedious.)

Re:What I wish I knew about React by karatestomp on Wednesday April 29, 2020 @09:55AM (#23019206)
> Animation in React Native is much more of a hassle than UIKit or even CSS. (About the same as native Android, though, where it's also pretty tedious.)

My experience was that RN was way more helpful on Android than on iOS, in general. But that has more to do with Android than RN, which achieves its utility on that platform by papering over a pile of bad decisions, inexplicable awkwardness, and half-finished-apparently-by-the-Summer-interns APIs, none of which should be problems in the first place. I'd seriously consider using it for just for Android even if I wrote a separate, native iOS version of the same app.

Re:What I wish I knew about React by iainmerrick on Wednesday April 29, 2020 @03:03PM (#23022853)
Yes, agreed!

The tools are starting to get fairly good on Android. There’s a lot to like about Android Studio. But the actual platform APIs are still a mess.

Re:What I wish I knew about React by partyboat1586 on Wednesday April 29, 2020 @04:09PM (#23023584)
The JS is run in a separate thread because the real-time operations are meant to be handled fully native. If you are constantly passing large amounts of data between the JS thread and the Native thread or constantly changing the layout (which passes data between the threads) you are doing it wrong. You can't code it like a web app where you just replace one large node tree with another if you want it to be instant, you have to mount both and keep one invisible, either using a navigation library or custom code. This way layout changes are smaller packets so it doesn't saturate the low bandwidth of the thread bridge.

The extra latency for a layout change is most noticeable if it's an animation hence why you should use native animations not JS polling animations. I agree the Animations API is not as easy as CSS. If you want to do complicated stuff you need a lot of experience with it. This is one of the major hurdles for new RN devs.

Its possible to get good performance our of it, better than mobile web UI, you just need to have some experience with what costs and what doesn't.

Re:What I wish I knew about React by LinguaBrowse on Wednesday April 29, 2020 @04:56PM (#23024184)
> If you are constantly passing large amounts of data between the JS thread and the Native thread or constantly changing the layout (which passes data between the threads) you are doing it wrong.

I’m working on an alternative to React Native that does exactly this, and it works absolutely fine: React NativeScript.

In NativeScript (and thus also React NativeScript), the JS logic and the UI both execute on the UI thread. Furthermore, you can synchronously access any native API without needing to set up bridging code; bindings to the whole Obj-C/Java runtimes are ready-generated.

https://github.com/shirakaba/react-nativescript

https://react-nativescript.netlify.com/

Re:What I wish I knew about React by iainmerrick on Thursday April 30, 2020 @07:46AM (#23029815)
Sounds great! After using RN for a while, that’s exactly how I think it should have been designed in the first place. Good luck!
Re:What I wish I knew about React by partyboat1586 on Wednesday April 29, 2020 @07:31PM (#23025835)
Sweet, no more bridge bandwidth issues. I'll check it out.
Re:What I wish I knew about React by iainmerrick on Thursday April 30, 2020 @03:48PM (#23035271)
If you are constantly passing large amounts of data between the JS thread and the Native thread or constantly changing the layout (which passes data between the threads) you are doing it wrong.

If I'm coding in a style that works fine on web, and also works fine in native code, but is slow in React Native, then I'd suggest I'm not the one doing it wrong, it's React Native itself.

This way layout changes are smaller packets so it doesn't saturate the low bandwidth of the thread bridge.

Even if they were to stick with the multithreaded architecture, it should be possible to build a layout structure in the background thread and just hand ownership over to the UI thread. I believe the RN team are working on doing this with their new Hermes runtime (sharing objects directly rather than marshalling them into and out of the JS engine), so that ought to help a bit. But I really think the threading model is just wrong-headed in the first place.

Its possible to get good performance our of it, better than mobile web UI

Is there a case study or even just an example that demonstrates that? I'm skeptical. Mobile browsers are very fast these days, so there's no obvious reason why RN should necessarily be faster.

I suppose RN might have an edge if you're making extensive use of native code. But then calling native code from RN is very laborious, so RN doesn't exactly pull its own weight in that scenario.

Re:What I wish I knew about React by partyboat1586 on Saturday May 02, 2020 @02:43PM (#23053924)
There are no benchmarks I know of, it's accepted wisdom that React Native is faster than mobile web even when not optimised and comes close to native when optimised. That has always seemed self evident to me but maybe it's time someone did some benchmarks.

I think the reason RN is faster is because mobile browsers have to support decades of crufty CSS in their layout engines while native layout engines are much more lean and ripe for optimisation. React Native uses Yoga layout engine so there may actually be benchmarks available on that.

Re:What I wish I knew about React by LinguaBrowse on Wednesday April 29, 2020 @04:54PM (#23024162)
> I don't understand why the JS is run in a separate thread, rather than just using the UI thread for UI (as it's intended for). By making all the interaction with the native toolkit asynchronous, it adds extra latency and leads to unavoidable glitches in native widgets used as controlled components.

Totally agreed. I’m working on an alternative to React Native that addresses exactly this: React NativeScript.

In NativeScript (and thus also React NativeScript), the JS logic and the UI both execute on the UI thread. Furthermore, you can synchronously access any native API without needing to set up bridging code; bindings to the whole Obj-C/Java runtimes are ready-generated to begin with.

https://github.com/shirakaba/react-nativescript

https://react-nativescript.netlify.com/

Re:What I wish I knew about React by runawaybottle on Wednesday April 29, 2020 @04:02AM (#23016637)
A whole lot of people use it at work and witnessed valid criticisms. It’s not like we’re going to have the knives out when React/Angular is new.

Give it a little time, see a few codebases, extend and build a few apps, then come back. Now people have some credible stuff to say. We can’t comment much about how great Hooks are after reading a few Medium posts. I’ll see in a few months when it’s all over the codebase.

HN will be full of ‘we rebuilt our api in GraphQl and boy things are a mess’ in 2 years.

Re:What I wish I knew about React by jsjw7sbw on Wednesday April 29, 2020 @04:20AM (#23016751)
We rewrote our frontend in hooks and graphql 1 year ago. Hooks are fine, but graphql is a messy time sink for our usecase.
Re:What I wish I knew about React by WiseWeasel on Wednesday April 29, 2020 @10:07AM (#23019379)
Did you also rewrite the backend for GQL? We've had great success and satisfaction with GQL, but it’s been limited to greenfield development so far. To me, one of the bigger wins with GQL on the front-end, aside from the obvious consolidation of requests, is access to react-apollo client's caching system, which can replace the use of state stores like redux for API data in many cases. I could see it being a challenge to rewrite a complex REST react app to GQL, since you'd be discarding a ton of data shuffling code, but we've been happy with the resulting simplification of our frontends.
Re:What I wish I knew about React by gregkerzhner on Wednesday April 29, 2020 @11:12AM (#23020186)
I don't understand this hype about Apollo. Its trying to be some strange "semi-framework" that takes care of some of your application concerns while actively making it harder to take care of the rest.

For example, Apollo will cache api requests, but what about local application state? Their local caching library is cumbersome to use. If you wanted to update local state, you either need to write a mutation, or manually fetch data from the cache and change it. For the former, I find writing GraphQL mutations more verbose and cumbersome than Redux.

In the latter, you need to worry about fetching, changing and saving state every time you need to make a change. With Redux on the other hand, your current state is fetched and saved for you automatically and you just need to worry about describing the state change in the reducer.

I also dislike the Query and Mutation components. The Query component can be fine for simple use cases, but it still ties your API calls directly to your component. What this often means that any business logic associated with the request goes in the component as well, leading your components to become bloated and untested.

The mutation component is even worse leading to super hard to understand code - you are basically writing your API request layer using HTML markup. For me its so much simpler to just have functions that call APIs directly instead of trying to understand some strange markup hierarchy.

In short, I can see the appeal of Apollo if your app had very little frontend state and just needed to be a reflection of the server. However, as your codebase grows in complexity, the patterns that Apollo encourages you to use lead to bloated and unmaintainable code.

Re:What I wish I knew about React by mikewhy on Wednesday April 29, 2020 @01:36PM (#23021887)
> For example, Apollo will cache api requests, but what about local application state? Their local caching library is cumbersome to use. If you wanted to update local state, you either need to write a mutation, or manually fetch data from the cache and change it.

Apollo is for GraphQL. I'm not sure why you'd try to use it's internal caching system to add local application stuff. Note that using Apollo does not stop you from continuing to use Redux.

> The Query component can be fine for simple use cases, but it still ties your API calls directly to your component.

This is what hooks aim to solve.

Re:What I wish I knew about React by WiseWeasel on Wednesday April 29, 2020 @04:08PM (#23023572)
The convenient thing about the Query and Mutation components being in your markup is the access to the loading and error states within that context. With Mutation, I often end up just passing the mutate callback to an event handler method. There's always direct access to the client when you want to make normal procedural API calls.

The Apollo caching system hasn’t been all roses; it can be pretty easy to wipe out parts of a cached entity you were needing on a view with the response to a mutation on a different view if you’re inconsistent with query and mutation response structure. But I find it convenient after getting the hang of its pitfalls.

Re:What I wish I knew about React by nsonha on Wednesday April 29, 2020 @10:17AM (#23019529)
> so you can scrap that entire connect() stuff alltogether

To me that "entire stuff" is about the only thing that is good about redux (barely does dependency injection). See people need to understand that hook is a good API from the library authoring point of view (the react team's and react component library authors') it's not such a clean abstraction for people to write application on top of while unneccesarily make their code depend on magic react functions all over the place.

I cant count how many "data fetching hook solutions" I've seen on twitter. If something does data fetching, then it needs to know about fetch() and may be a reactivity abstraction like promise or rx. A hook is completely unjustified.

Re:What I wish I knew about React by acemarke on Wednesday April 29, 2020 @10:26AM (#23019625)
Hi, I'm a Redux maintainer.

Hooks definitely lead you towards a different approach for writing components with a different set of tradeoffs. I talked about this in my post "Thoughts on React Hooks, Redux, and Separation of Concerns" [0], and my ReactBoston 2019 talk on "Hooks, HOCs, and Tradeoffs".

For React-Redux specifically, `connect` still works fine and we will be supporting it indefinitely. However, we're now recommending that people use our hooks API as the default approach, because it's typically simpler to work with and there's less indirection.

[0] https://blog.isquaredsoftware.com/2019/07/blogged-answers-th...

[1] https://blog.isquaredsoftware.com/2019/09/presentation-hooks...

Re:What I wish I knew about React by have_faith on Wednesday April 29, 2020 @08:44AM (#23018396)
I think the number of concepts that need to be understood to be an efficient React developer has grown over the years just enough that it has become slightly frustrating to learn. It is still presented as a very simple small surface area framework but there's a lot of subtly with how many new concepts need to be understood now like hooks as an example. I think it just crossed a threshold and became less intuitive and more tiresome as a result unless you are embedded in React land and do React stuff all the time.
Re:What I wish I knew about React by dbbk on Wednesday April 29, 2020 @11:11AM (#23020174)
The useEffect example in this article to me is ludicrous. It makes absolutely no sense just looking at it.
Re:What I wish I knew about React by tarsinge on Wednesday April 29, 2020 @07:26AM (#23017908)
> I am not so up to date with frontend dev but what's with the hate towards React these days?

I don't use React day to day in a big team so I can't comment on the maintainability gains, but as a user all I see is websites degrading the experience when migrating to SPA. If state of the art front end engineering with React is Facebook or Reddit then it's hugely disappointing.

Re:What I wish I knew about React by Alterlife on Wednesday April 29, 2020 @04:42AM (#23016865)
Does this article qualify as 'hate' though? The author acknolwdges that he's new to react and is simply pointing out two things that he found challenging.

Nothing surprising. Infact, I don't understand why the article is so highly upvoted.

Re:What I wish I knew about React by jchw on Wednesday April 29, 2020 @04:43AM (#23016882)
This was my first thought, but the parent comment is probably referring to the comments that were on top at the time it was written, rather than the article (which I agree, is fairly mundane, although I think it’s fine.)
Re:What I wish I knew about React by yakshaving_jgt on Wednesday April 29, 2020 @05:44AM (#23017267)
I don't think the author is a "he".
Re:What I wish I knew about React by Kiro on Wednesday April 29, 2020 @04:56AM (#23016967)
HN is a pretty hateful place in general.
Re:What I wish I knew about React by gitgud on Wednesday April 29, 2020 @10:30AM (#23019675)
If you're coming from Reddit, Imgur or YouTube it seems like hate, but I've found it's simply a lack of humor...

Any jokes, memes or puns are frowned upon the community 99% of the time. I suppose it's considered redundant or not-constructive...

Re:What I wish I knew about React by hombre_fatal on Wednesday April 29, 2020 @12:11PM (#23020864)
That's only because 99% of jokes aren't as good as people thought they were when they pushed the submit button.

HN has a great sense of humor. I know this of course because my jokes have been upvoted.

Re:What I wish I knew about React by gitgud on Wednesday April 29, 2020 @06:57PM (#23025549)
Most jokes I see are downvoted and I can't recall seeing a single joke comment. That's not to say there zero humor here, just much much less than other less serious discussion forums.
Re:What I wish I knew about React by cambalache on Wednesday April 29, 2020 @01:48PM (#23022025)
That is true, but it not just the lack the humor, it is the pretentiousness and the faux-politeness.
Re:What I wish I knew about React by gitgud on Wednesday April 29, 2020 @07:03PM (#23025605)
Well being nice and polite is part of the guidelines here, which is not such a bad thing.

But the pretentiousness annoys me sometimes, at the end of the day it's another forum of people who don't think they're part of a hive-mind... which we definitely are

Re:What I wish I knew about React by cambalache on Wednesday April 29, 2020 @07:39PM (#23025892)
Being nice is great, being fake-nice is not, sometimes politeness is a facade to hide passive-aggressiveness and up-you-up-manship.

HN readership is as establishment and conventional as it goes, it is the "study hard for the SAT/GRE/GMAT" crowd.

Re:What I wish I knew about React by krapp on Wednesday April 29, 2020 @02:02PM (#23022183)
It's an elitist mirror to 4chan's edgelord culture in many ways.
Re:What I wish I knew about React by cambalache on Wednesday April 29, 2020 @06:20PM (#23025183)
if only, for all their sins (which are lots) 4chan is a very fascinating place. The other day I was fantasizing (lol) about giving a talk to out-of-touch academics/journalist boomers and explaining them the 4chan phenomenon.

There are lot of very smart people there. You compare the recommendations in music/books/cinema between them and reddit and it is "People" vs "Cahiers du Cinema".They tend to create lots of Internet culture, the humor is caustic but it can touch genius from time to time and they are very open regarding topics like sexuality,depression, economics and so on.It is proof there is always more that meet the eye.

Re:What I wish I knew about React by krapp on Wednesday April 29, 2020 @07:47PM (#23025962)
>You compare the recommendations in music/books/cinema between them and reddit and it is "People" vs "Cahiers du Cinema".

My point is there are affectations in both communities (4chan and HN) that are strange opposites of one another. Here, people often pretend to be more polite and erudite than they are, there, people often act more rudely than they normally would, because that's the culture, that's the mask you're expected to wear.

And on both sides there's a pretension which you're kind of displaying. You're talking about a site as vast and varied as Reddit as a whole as if it were a single forum, and dismissing it as qualitatively lesser than an anonymous imageboard that has shitposting as a central part of its identity. Find some well moderated subreddits for any particular genre and you'll find quality of conversation equal to anything on 4chan, or even HN.

Also, you know, 4chan has been around long enough at this point that a lot of "out of touch academics" and "journalist boomers" have probably been there.

Re:What I wish I knew about React by cambalache on Wednesday April 29, 2020 @08:58PM (#23026389)
On the contrary, that is the refreshing part of 4chan, the unpretentiousness, a guy can talk about Nietzsche using memes and somehow make a good argument. Reddit is pretentious without any reason for it to be, at least here in HN there are competent people. And I was comparing the lists of recommended books of r/books vs its equivalent in 4 chan, as far as an apple vs apple comparison goes.
Re:What I wish I knew about React by nurettin on Wednesday April 29, 2020 @05:41AM (#23017249)
I'm not sure if the stuff I see in HN threads qualify as hard feelings. They are more like jabs, prods, cheap shots, demands, begs and lots of bikeshedding with a smither of useful information here and there. I do appreciate the fact that they try to discourage the reddit style of rimshotting.