News for hackers. Stuff that matters.
Re:React Fundamentals: What I’m Learning by archsurface on Tuesday November 03, 2020 @01:29PM (#24982464)
Interested to see this because I'm neither a JavaScript nor frontend dev, but over the last two weeks have been gently learning React out of curiosity, applying it to a small personal project. The last time I used JavaScript was with Angular 1.x around 2013. Iirc the angular learning curve was negligible; React's is steeper, but I can't compare with modern Angular - seems it's up to 11.rc1. I get the impression React has mostly won the battle. I was wondering if maybe I should have tried Svelte instead, but React is the name I keep seeing, so figured that's where I'll peek (first?). I think the muddle I need to sort through at the moment is the old tutorials vs the new tutorials as I'm seeing multiple ways of doing things but don't yet know which are the new ways, the best practices, or the trade-offs with each.
Re:React Fundamentals: What I’m Learning by ritchiea on Tuesday November 03, 2020 @03:40PM (#24983726)
The latest consensus is to avoid class components, use only functional components and use hooks to handle state & side effects. Ninety percent of React is building DOM, hitting APIs with an HTTP client and using useState + useEffect. And remembering that you must pass functions & data to child elements to communicate between or share logic across components.
Re:React Fundamentals: What I’m Learning by poyu on Tuesday November 03, 2020 @07:42PM (#24985676)
What’s the reason to avoid class components though? The official tutorial still uses it, though that could just be because it’s outdated?
Re:React Fundamentals: What I’m Learning by acemarke on Wednesday November 04, 2020 @11:36AM (#24990524)
The React team is currently working on a complete rewrite of the docs, which will include a focus on hooks first:

https://github.com/reactjs/reactjs.org/issues/3308

In the meantime, someone else ported the existing docs to teach function components and hooks in the examples:

https://reactwithhooks.netlify.app/

Re:React Fundamentals: What I’m Learning by ritchiea on Tuesday November 03, 2020 @08:17PM (#24985857)
The zeitgeist is that hooks are easier to reason about than life cycle methods, functional components are more lightweight and result in less bundled code.
Re:React Fundamentals: What I’m Learning by hitekker on Tuesday November 03, 2020 @09:35PM (#24986140)
It's more of a hype train than a "zeitgeist". Major community contributors like Jared Palmer have stepped forward in the past year to critique the complexity of React hooks.

https://jaredpalmer.com/blog/react-is-becoming-a-black-box

https://dillonshook.com/a-critique-of-react-hooks-addendum/

Personally, I think blindly adopting the latest frontend trends is the opposite of being "radically pragmatic".

Re:React Fundamentals: What I’m Learning by ritchiea on Wednesday November 04, 2020 @03:38PM (#24992824)
What's more pragmatic than not being precious about what technology decision is most perfect and instead going with what's popular and has a lot of community support?
Re:React Fundamentals: What I’m Learning by ritchiea on Tuesday November 03, 2020 @10:28PM (#24986283)
Ok! Your opinion is noted
Re:React Fundamentals: What I’m Learning by bluedevil2k on Tuesday November 03, 2020 @04:20PM (#24984126)
Stay with React, don't go with the newest shiniest JS framework. React has a 3rd party solution for nearly everything so you can piece all these well-developed and well-tested modules together to make your app.

Others may suggest using Hooks right from the start, so I'll act as the counterpoint. Starting with Class components is easier to understand and less is happening magically. Almost everything can be accomplished using only 3 lifecycle methods - constructor, render() and componentDidMount. Once you're comfortable with how that all comes together, start to pick up Hooks

Re:React Fundamentals: What I’m Learning by richeyryan on Wednesday November 04, 2020 @03:31AM (#24987305)
If you are doing asynchronous data fetching in your components, only using those three lifecycle methods will inevitably lead to bugs when your props or state update but your asynchronous call doesn't fire again because it was in componentDidMount. You need to use componentDidUpdate to trigger the call again when props or state update. Alternatively useEffect with the dependency array properly filled won't allow a stale state like that to occur.
Re:React Fundamentals: What I’m Learning by csomar on Tuesday November 03, 2020 @04:22PM (#24984161)
React is indeed very steep, but it is very productive if your application is complex enough. If you are going to use Static Site generation (react-static) and GraphQl (relay), then React quickly pays off.

My experience with Vuejs/React is that Vue is easy to start with and good enough. But once you need more integration with the ecosystem, you realize that React has better support.

Re:React Fundamentals: What I’m Learning by dragonwriter on Tuesday November 03, 2020 @04:26PM (#24984200)
> Iirc the angular learning curve was negligible; React's is steeper,

Almost everyone I've encountered has found React easier than Angular, though React is more prone to lead you into analysis paralysis with options, since it covers less OOTB and there are so many alternatives that interact with React for each of the other bits.

Re:React Fundamentals: What I’m Learning by agustif on Tuesday November 03, 2020 @02:15PM (#24982910)
Good call on React vs Angular, Although Svelte is the newest cool kid in town, I'd rather go with Vue than Svelte.

Also NextJS is the best way to learn React IMHO, but it adds a lot of extra stuff so maybe wait until you need it

Re:React Fundamentals: What I’m Learning by davidwparker on Tuesday November 03, 2020 @03:42PM (#24983743)
Besides the bigger ecosystem, curious as to why you'd go with Vue over Svelte?

I've used Vue for pet projects but Svelte a lot over the last 6-months and don't think I would reach for anything else but Svelte right now. (I'm sure that opinion will change over time, but between the speed of development, and the incredibly nice / fast applications I'm able to build, I've never felt more productive (on the frontend))

Re:React Fundamentals: What I’m Learning by preommr on Tuesday November 03, 2020 @04:01PM (#24983921)
I like vue a lot more.

In regards to the ecosystem, tooling is much better for vue. In fact, given how similar react/vue/svelte are, the tooling makes a big difference.

Other than that, I like that vue (ironically) has less magic than svelte. If I wanted to switch over to react, I could just use react+mobx for pretty much the same experience. Vue's reactivity is basically very simple observables that I can easily envision in my head. Even though it uses a dsl - there are like 6 directives that I have to remember that are pretty much common to any template engine (i.e. v-for, v-if, etc). Whereas, svelte has a lot more magical syntax that makes it perhaps more pleasant to program in, but not something I am willing to invest in until it becomes more mature.

I use the object style for components and really like it because it makes things more explicit and clear. I know svelte is smaller and so it's more productive for smaller use cases, but in the long run, I like the more explicit nature for when I am switching between front-end and back-end.

Also, vue is a lot easier to integrate incrementally since it does a fair amount of stuff during runtime in contrast to svelte which does the main work at compile time. The latter obviously makes it a little bit faster, but the web environment is slow enough that my other techniques (like lazy loading) are enough to cover for it.

Re:React Fundamentals: What I’m Learning by davidwparker on Tuesday November 03, 2020 @06:51PM (#24985359)
I've found Svelte's tooling to be great. Can you elaborate on what's lacking and what Vue provides that's better?

I come from a Rails background, so I don't tend to find anything "magical". I guess to me, it's all pretty simple so long as you take the time to read how it all works. (I understand not everyone has time to do that).

I'm not sure about the incremental stuff- it may be that I'm used to it going fast. You should also checkout the latest Svelte (not public yet) from Rich, it's able to automatically show updates after every save, with state being kept within the refresh.

Re:React Fundamentals: What I’m Learning by xxffgg557 on Tuesday November 03, 2020 @03:23PM (#24983572)
Thinking react vs. angular as though they are trying to "win" some universal battle is just propagated by clickbait blogging. Enterprise + larger scale teams tend towards Angular, blog posts and hip projects tend towards react.
Re:React Fundamentals: What I’m Learning by bluedevil2k on Tuesday November 03, 2020 @04:22PM (#24984153)
I disagree with this statement. The last 3 projects I've been on, all huge enterprise level projects, have all been React. Angular was purposefully not picked on the first project because it gets hard to maintain on huge projects, and the last 2 projects were moving existing Angular apps to React for that same reason.
Re:React Fundamentals: What I’m Learning by maclockard on Tuesday November 03, 2020 @03:44PM (#24983771)
I don't think this distinction is exactly correct. I've worked on some enterprise projects with larger scale teams that have used React. It offers a bit more control than Angular does in terms of what your frontend 'stack' is comprised of. This level of control can be appealing for large projects.

I kinda see a trend that projects started after x date tend to use React over Angular, but I am unsure of what x is or how universal this is.

Re:React Fundamentals: What I’m Learning by xxffgg557 on Tuesday November 03, 2020 @04:21PM (#24984135)
Obviously some enterprises have used either. This is not about subjective experience.

Regardless, it should be obvious to anybody that has ever worked in a massive corporation that a DIY approach with react will not be opted for. Talking about the corps where most people get jobs, not the ones that publish blog posts on hacker news

Re:React Fundamentals: What I’m Learning by dragonwriter on Tuesday November 03, 2020 @04:33PM (#24984258)
> Regardless, it should be obvious to anybody that has ever worked in a massive corporation that a DIY approach with react will not be opted for.

While it's public sector, I work for a fairly big, boring, enterprise org that doesn't publish anything on HN and for our apps that use a SPA framework, a “DIY approach with React” is pretty much exactly what we are doing,at least in my corner of the org. Never heard of anyone in the org using Angular (there's some shops doing jQuery/Bootstrap stuff, and some at least experimenting with Blazor which isn't surprising given how .NET-heavy the org has been.)

There was a time when Angular was sort of the enterprise Java of SPA frameworks, but I think that's kinda past already, and lots of big boring enterprises missed it completely.

Re:React Fundamentals: What I’m Learning by maclockard on Wednesday November 04, 2020 @04:21PM (#24993176)
In my experience bigger companies seem possibly _more_ prone to a DIY approach than scrappy startup. Especially if there is a 'not built here' mentality.
Re:React Fundamentals: What I’m Learning by nfRfqX5n on Tuesday November 03, 2020 @04:19PM (#24984114)
yes, hip "projects" like as facebook, airbnb, walmart, nytimes, netflix use react