TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: Why React?

21 点作者 loughnane11 个月前
I&#x27;m a self-taught programmer and stumbled my way into using htmx + alpine + django for a project. The usual case I hear for why to use react at all is because it manages state well, but even from my naive perspective I seem able to do what I need to do (handling several modes where functions vary based on those modes) using Alpine.store.<p>I know barely anything about react, but I&#x27;d love to get your takes as virtually all of you are more experienced than I am. Why react in general?

21 条评论

schwartzworld11 个月前
React embraces one-way data flow. You build a tree-like structure of components each of which is configured by the props passed to it by its parent. Each component is a function that runs again every time any of the props change. Components also have the ability to manage local state, which is simple in some ways but handled poorly can lead to a lot of complexity. React doesn&#x27;t give you a lot of guard rails, but it does give you a lot of power. You can tell the best React developers by how they handle state and side effects.<p>Most of your components in a React app should be pure functions, meaning their output for a combination of props should be the same every time. This makes testing extremely easy, although YMMV depending on how you structure your app. React lets you write lots of cheap and almost unbreakable lego pieces that you can assemble into larger blocks of functionality.
neontomo11 个月前
I haven&#x27;t used your stack, but my main benefits of React are:<p>- People will pay me to build with it<p>- State - Update a value and all the places that uses the value get updated without any extra fiddling. If your pages are very dynamic or uses lots of use interaction you skip a lot of complexity<p>- Components - All components end up in their own file, adding reusability and clarity to the logic<p>- NPM packages - Easily add extra functionality<p>- JSX - It&#x27;s a delight to write &quot;HTML&quot; and embed variables and functions directly where you need it
评论 #40653092 未加载
adamredwoods11 个月前
When you have 20 teams building all kinds of features, React is a common, familiar platform with re-usable components. Teams can interchange smoothly, good for retaining and training employees. Well supported, large community, standard testing, a11y, security updates.<p>For small, one-time projects? Use whatever makes you and your client happy. Just be aware it will be outdated in 5 years, so who will maintain it?
victorbjorklund11 个月前
Huge HTMX fan but there are some things that just going to be easier to build with a real SPA. For example not going to be a great experience to build spotify using just alpine and htmx.
skydhash11 个月前
The standalone React library is okay. The virtual dom is not that necessary to do frontend, but it&#x27;s at the core of what React is adding an extra layer of separation between the DOM and React concepts. But other libraries have shown that it&#x27;s not that necessary.<p>The issue is the ecosystem. There&#x27;s a lot of complicated architectures out there which only apply in esoteric context. Another issue is with the tooling. More often than not, we have templates that advertises making things simpler, but instead promotes complex and complicated tools that you should not add to your codebase.<p>But more often than not, you only need to update the content of your web app, and do a few changes to the layout. For that you don&#x27;t need a full blown frontend library. React shines when you want to do web applications, not websites. But they&#x27;re all pretty much the same when it comes to the latter. htmx+alpine and the other similar solutions are better when you don&#x27;t want to control the whole UI. But need to add interactivity to a few select place. Which is the majority of websites.
dysoco11 个月前
This is similar to asking why Unity for a 2D game when something like SDL&#x2F;Pygame&#x2F;Love2D will work... sure it will and probably will be much cleaner for smaller, simpler things but I couldn&#x27;t phantom building something with a lot of interactivity, popups, drag and drops, interaction, etc. with just HTMX and Alpine, and you get a massive ecosystem of UI libraries with premade theming, etc. Plus now React has NextJS which also gives you backend and SSR capabilities into one cohesive solution.<p>htmx looks really cool to me and I probably would chose it if I were to build something like Hacker News with little interactivity where I just need to show a few things reactively, but it&#x27;s just not the right tool for all applications.<p>Even if you build something simple and small you can use a small subset of React without any complex frameworks or libraries, just as a single library, and it will work fine and won&#x27;t be too complex.<p>Disclaimer I have not used React extensively although I did work at my dayjob with Vue which is very similar.
wil9711 个月前
My answer would be the ecosystem, let&#x27;s say you&#x27;ve to implement a note editor, a calendar and a dnd module and what not. You move fast because it has already been solved. And you don&#x27;t reinvent the wheel.<p>Also have a look at the frontend iceberg there&#x27;s a lot more to frontend systems.
codegeek11 个月前
I don&#x27;t use React much but you are asking a question that was asked of Angular when react came a decade or so ago. Before that, people have always been asking &quot;Why JQuery when you have angular etc&quot;<p>It is just a matter of time before someone goes &quot;Why HTMX&#x2F;Alpine ? Now we have this &lt;replace with the latest new shiny thing&gt;&quot;<p>Point is that the JS ecosystem is always coming up with new stuff. And there is a use case for all of them, React included.
fracternal11 个月前
My preferred stack is nextjs (react based) on the front end and either Django or fastapi on the backend. React allows you to build mvps really fast, handle states very well and has a lot of hooks you can use.<p>The downside to this is it makes code heavy sometimes. I use nextjs because I love the server side rendering and seo optimization it provides and use the client components (traditional react) to manage state.
meiraleal11 个月前
To give the user a responsive and offline-first experience and also to scale infinitely without the need to provision a server for it - don&#x27;t use nextjs! If you use nextjs every advantage is gone so it would be better to stick with django
wruza11 个月前
With react you can get paid 2x more if your employer has react. That’s about it. Otherwise any modern framework will do, just use what has enough stars and less than 2-3 major versions in last few years.
andrei_says_11 个月前
Do you (like someone mentioned in the comments) plan to build something with the complexity of Spotify or Gmail or Facebook? And don’t have a team of dedicated front end engineers? If this is the case, React is for you.
lulznews11 个月前
It just works and is closer to programming than writing god awful html.
hiAndrewQuinn11 个月前
I just always try to master the most popular tool of a given area first before I start exploring around. Call it a generalized Chesterton&#x27;s fence.<p>React happens to be the most popular tool, and I find a lot to like about it.
masfoobar11 个月前
I am (mostly) a backend developer - so I deal with languages like C#, communicating with databases like MySQL, SQL Server, etc.. and sending data back (to things like) the frontend, such as HTML&#x2F;Javascript.<p>Despite this - I <i>can</i> do frontend development as well - but I have reached a point where I cannot be asked to learn new Javascript framework or libraries. Personally I just think it has become bloated, so I leave that for those that do know&#x2F;understand.. like full-time React developers. I cannot be bothered as I am sure some new toy will come out in the next few years and replaces it.<p>My opinion... and I understand it is apples and oranges... is web development could be much easier than it is today. Back in &#x27;00s we were using old school PHP or Classic ASP to return compiled HTML content and, mostly, full screen refreshes. Eventually, Javascript gained more responsibilities giving us JQuery. We had simple GET and POST functionalities, allowing us to refresh part of the page, etc.<p>By around the 2010&#x27;s I remember KnockoutJS and, eventually, AngularJS. Web development was changing and I accepted this. While I saw some benefits with auto refreshing hooks or the like.. the end was a lot of bloat... more lines of code. Some of which is duplicated in the frontend as well as the backend.<p>Between 2016 to 2021 I stopped web development. I started a job as a GUI application developer. When I returned to web development I am now seeing Node being used... Grunt being used... with some websites sticking to JQuery while another is using React. I am in shock at how complicated things has gotten!<p>To me, with my years of experience, feel like I am going full circle back to the old methods of web development... just with modern tools! I leaned back to jQuery for personal projects. It is easy to follow (in my opinion) -- but I came across HTMX in 2023 and really enjoying it!<p>Using HTMX, With odd exceptions, my javascript code is mostly a compliment to my CSS. The amount of code is reduced by 60-80%!<p>Since then I have started using HTMX for web projects at work -- with positive feedback from the team. We are, one by one, moving our projects over to HTMX. It is just easier to deal with.<p>Our team only has half a dozen developers. We are mostly backend devs but OK with react. Some are better than others. We have agreed that with HTMX we are getting things done a lot easier. We no longer have to bother with the additional layer that is React. We also stopped using jQuery.<p>Now I am not suggesting HTMX replaces React for all cases. Its just, for our use cases, it has done the job remarkably well.. and we are doing complicated web sites.<p>Having a team of React devs may be needed in a number of scenarios - I, thinking of all websites I have built over the last 20 years, struggle to find one.<p>There is a saying that is going to offend, but I think those that dislike or hating on HTMX are those that have invested their time on (things like) React. I also hear that HTMX guys are like a cult. That might be true to a degree. I am sure some will suggest I am one of them with this comment.<p>- React creates jobs, but HTMX gets rid of them.
评论 #40645322 未加载
reneberlin11 个月前
You came late to the party, but in short, yes you are right: you can skip the excesses the frontend-world got into and use the minimal needed tools to do the job. Every line of code costs time and money, but do not try to explain that to a Typescript&#x2F;React-fellow or Angular-Fanboys.
评论 #40656660 未加载
nathants11 个月前
because: <a href="https:&#x2F;&#x2F;reagent-project.github.io&#x2F;" rel="nofollow">https:&#x2F;&#x2F;reagent-project.github.io&#x2F;</a>
aristofun11 个月前
Complex and heavy UI - that&#x27;s why basically.
pootempy11 个月前
Main reasons for me:<p>I know it. It is good enough. It is fast enough. DX is good enough although edges are prickly in functional&#x2F;hooks. Massive 3rd party support. Does everything from simple to SPA that could make Slack work for example without a tech switch.
solardev11 个月前
I&#x27;m a self-taught programmer too (and a web dev of like 15-20 years)... can give you one opinion (and that&#x27;s all this is).<p>IMO it&#x27;s important to discuss two related but separate things:<p>1) Why an interactive frontend at all? IMO this is the more important question, and basically boils down to &quot;AJAX enables better UX since you&#x27;re not refreshing the entire HTML on every page load&quot;. It&#x27;s better (in theory) for end-users because actions and screen loads should be a lot quicker.<p>But that&#x27;s only relevant when comparing to serverside frameworks (like old PHP, cgi-bin stuff, old government websites, etc.). Most modern frameworks have moved to this model, and even the old PHP stuff uses it piecemeal.<p>That answers the &quot;why a frontend framework at all&quot; question, but not &quot;why React&quot; specifically, when Alpine&#x2F;Vue&#x2F;Svelte&#x2F;Anything Else can do a similar job.<p>2) My answer to that is simply &quot;momentum&quot;, and that&#x27;s because of history. React did what AngularJS (v1) tried to but could not: gained critical mass. For a while there, it was the only major option for teams that wanted to build an enterprise-grade frontend that could be easily shimmed into their existing backend, without the overhead and overcomplexity of Angular. React then was more of a UI library than an actual framework like Angular, and so you could jam in React anywhere you needed it, but leave it out where you didn&#x27;t need it.<p>(These days that&#x27;s of course changed with frameworks on top of React like Next.js, which adds a lot of features and preconfiguration for a one-click deploy.)<p>But I don&#x27;t think those features are why people choose React for new projects. It&#x27;s again the sheer <i>momentum</i> of React. It&#x27;s here to stay, it&#x27;s well-supported, it has a huge ecosystem, and – importantly – it&#x27;s easy to hire and train for. It&#x27;s the most popular standard for the time being.<p>You can hire any off-the-shelf React dev and they can start working in your recent-ish React codebase (especially if it has no older-style class components anymore) without much additional training, because they can take your existing state object and easily build a new component on top of it and make a workable screen. But it&#x27;s not <i>just</i> that... it&#x27;s that they can move to another team, and they&#x27;re <i>probably</i> using React too. And when they switch companies, it&#x27;s probably <i>still</i> React. It&#x27;s a skillset that has a moderate learning curve (it&#x27;s really not so bad if you spend a few days on it) but then can keep getting reused at many many places and career opportunities.<p>By contrast the other frameworks might have many of the same important features, but they&#x27;re nowhere as easy to hire for, and there&#x27;s no guarantee of their future popularity&#x2F;sustainability. The JS frontend world moves really really fast, and there was a period a few years ago where entire frameworks and languages (CoffeeScript, Backbone, Knockout, Ember, and of course Angular) came and went, much hyped initially but then quickly fell out of fashion in 1-2 years.<p>By contrast, React and Next is very firmly entrenched now and probably will stay that way for a while; they&#x27;ve become the Wordpress&#x2F;Drupal of the frontend world, the &quot;good enough&quot; default option that many teams will default to.<p>Of course individual teams can evaluate different frameworks and choose the one most suited to their needed complexity level, but if you don&#x27;t want to think about it and&#x2F;or want to maximize the chances that your codebase will still be maintainable by a new team a few years from now... it&#x27;s probably gonna be React. Not because it&#x27;s the best, but just because it has too much momentum to die in the short term.<p>At a certain scale (small-to-medium-sized businesses), it makes sense to just use a &quot;good enough&quot; option that&#x27;s widely used across the industry, because it&#x27;s easy to find help for. When you&#x27;re tiny (like a restaurant website or a blog or just a simple ecommerce company) it doesn&#x27;t matter much because your codebase probably isn&#x27;t complicated enough anyway to justify React, and whatever you do is probably going to be pretty janky anyway. When you&#x27;re huge, you can design and maintain your own framework (after all, that&#x27;s what Meta did with React). But in the middle, where most companies are, there&#x27;s not really a good business reason to choose one of the dozen+ smaller frameworks when React will almost certainly do the job and there are so many devs for it. It&#x27;s like &quot;no one ever got fired for choosing React&quot;.<p>It could&#x27;ve been anything, really. There is no perfect framework, just frameworks that gained enough critical mass or didn&#x27;t. Google really wanted it to be to be Angular, Microsoft wanted it to be .NET, but now everyone (at least in the US) just uses React. I think .NET is more popular in Europe. Once one of these frameworks gains enough popularity, it&#x27;s really hard to altogether displace it. React got in at the right time, got enough critical mass, and the rest is history... regardless of its technical merit.
revskill11 个月前
Because PHP sucks.