| ▲ | gloosx 8 hours ago |
| React isn’t just "winning by default" It's winning because at the core it's just JavaScript function composition. A component is a function, conditionals are `if (...) { ... } else { ... }`, loops are `map()`. JSX is just sugar for function calls. In Svelte you are writing XML with little JavaScript islands inside it. Instead of if you get `{#if}{:else}{/if}`. Thats not "ergonomic" – thats a mini-language stapled on top of JS. No one wakes up saying "please let me write control flow in XML today" The compiler tricks are neat, but React feels natural because it never asks you to stop writing JavaScript. |
|
| ▲ | mike_hearn 8 hours ago | parent | next [-] |
| So JSX is pure Javascript and not, say, a dialect of XML embedded in JS? Because it sure looks like the former even though it compiles to the latter. React isn't Javascript. It's a franken-language that looks superficially like a mix of JavaScript and XML whilst following the rules of neither. That's why there is such a thing as a React compiler - a good sign that you're not writing JS, which doesn't have compilers. The other hint should be all the new rules you have to follow. React is full of magic syntax that looks like functions, but e.g. you can't call them inside an if statement, or you have to redundantly declare the 'dependencies' (variables you read) and so on. The semantics of React code are very different to imperative straight line code. |
| |
| ▲ | jbreckmckye 8 hours ago | parent | next [-] | | > So JSX is pure Javascript and not, say, a dialect of XML embedded in JS? It would be best to think of it as syntax sugar for create Element() function calls. You enter JSX with angle tags and insert expressions in braces > React is full of magic syntax that looks like functions, but e.g. you can't call them inside an if statement, or you have to redundantly declare the 'dependencies' (variables you read) and so on That's not magic syntax. That's just functions that must be processed in regular order between render ticks. It's not a difficult exercise to write a "plain JS" function that works that way. If you've worked much with closures you can visualise how that would play out. | | |
| ▲ | conartist6 5 hours ago | parent | next [-] | | Hooks are magic syntax without any doubt. All magic syntax is made up of non-magic parts, that's kinda the point. The way you know it's magic is it shatters the principle of referential identity, which tells you that a variable is itself. It pretends you can use a simpler mental model but you really cannot and must not. | | |
| ▲ | snemvalts an hour ago | parent | next [-] | | You can write const [a, b] = useState('x') in vanilla js and typescript. Hence it is not magic syntax. | |
| ▲ | jbreckmckye 4 hours ago | parent | prev | next [-] | | > The way you know it's magic is it shatters the principle of referential identity, which tells you that a variable is itself When you do a useValue() it is clear you are grasping at something with a larger lifespan than your function. Conceptually it is not much different than int counter() {
static int x = 1;
return x++;
}
Which predates C89, if age is an argument | |
| ▲ | imtringued 4 hours ago | parent | prev [-] | | Hooks aren't magic syntax. The problem with hooks has nothing to do with syntax. The problem is that the React crowd has decided to overload the meaning of a term that has had a reasonably solid interpretation (at least in comparison to the React crowd). "React Functional Components" have nothing to do with conventional functional programming. They inherently (intentionally?) violate the spirit of functional programming through hidden global variables, while pretending that it is still functional, when in reality they should be doing the opposite. They should be upfront about the hack that hooks are. They are not functional, they are merely functions. In all other respects they operate as if the function was a method inside a class and that all hook calls are with respect to an invisible "this" keyword that contains the component's context. Since hooks are not named (which would expose their inherently pseudo-OOP nature), they associate their state through a hidden incrementing counter. It's like you're sweeping all the OOP parts under the rug to pretend to be functional so you can be a cool functional hippie too. | | |
| ▲ | StopDisinfo910 8 minutes ago | parent | next [-] | | > They are not functional, they are merely functions. Functional literally means dealing with functions composition. Free of side effect is not a property of functional programming. Ocaml is functional and has side effects. | |
| ▲ | recursive 12 minutes ago | parent | prev | next [-] | | What makes it even worse is that in order to match the hidden state with the output of a render function, it has to be "reconciled" which uses usually-right heuristics to match the tree structure of the function output to the tree structure in the fiber cache. | |
| ▲ | svieira 3 hours ago | parent | prev | next [-] | | Aren't hooks just composable effects implemented in userland? In fact, Sebastian actually asked the ECMAScript committee for effects a la OCaml 5.0 effects (https://ocaml.org/manual/5.0/effects.html) and React only built their own when the committee said "not right now", if I remember correctly. The thing is ... you can model effects with the Free monad (or with Haskell's Backpack as was on here just the other day - https://news.ycombinator.com/item?id=45221112), so they are definitely "functional", for most variations on the definition of "functional" that I know. | |
| ▲ | mike_hearn 3 hours ago | parent | prev | next [-] | | Yes, that's exactly it. React is presented as functional but it's still just stateful components, except instead of OOP syntax and features making that clear, it's hidden away so that it looks functional without actually being so. This happens because GUIs are inherently imperative constructs. | |
| ▲ | TomaszZielinski 3 hours ago | parent | prev [-] | | Yeah, well put tech wise (the ad personam part puts me off a bit, though). Personally I like hooks quite a lot, but e.g. I feel I have to check once a month or two if a memoized component (that’s „functional” in name) re-renders if its props stay the same and the only change is the state.. |
|
| |
| ▲ | burnerzzzzz 6 hours ago | parent | prev [-] | | > It would be best to think of it as syntax sugar for create Element() function calls Thats what makes it a new language. C is just sugar on top of assembly. Its so strange that jsx needs a buildstep, but misses ton of obvious ergonomics that one could have added. Why className
instead of class? With a buildstep, it would surely be possible to determine if class was a keyword or not based on context | | |
| ▲ | jbreckmckye 6 hours ago | parent | next [-] | | > Thats what makes it a new language. C is just sugar on top of assembly. I think that's a bad example. C isn't a sugar for assembly: For example what assembly code does a function prototype desugar into? Sugars have 1:1 mappings with host code Maybe you're just being rhetorical about the spectrum of macros, sugars, and languages, though. (In my opinion, a better target for that criticism, in JS land, is the Jest test framework, because of all the reordering magic it does that break fundamental ES semantics) > Why className instead of class? This hasn't been a constraint since... I want to say React 18, six or seven years ago? I might be misremembering the history but I think that was only a problem in the Early Days when there was paranoia about whether JSX needed to be conservative with reserved keywords | |
| ▲ | rafaelmn 5 hours ago | parent | prev [-] | | Syntax sugar is language syntax that improves a common pattern from the language (making it sweater). jsx, async/await - things that just abstract common patterns. |
|
| |
| ▲ | tayiorrobinson 7 hours ago | parent | prev | next [-] | | > That's why there is such a thing as a React compiler - a good sign that you're not writing JS, which doesn't have compilers. You say that like it's a bad thing - but it didn't stop Babel or TypeScript from being popular, both of which need a compiler. And being honest, I don't like extra tools in my chain, which is probably why I don't use React proper, but that proves you don't need anything React specific for anything other than optimisation The only syntax you really want for React is JSX. Which is just because writing React.createElement("div" ...) every time is unergomomic. JSX isn't specific to React. It could easily be a language feature, in fact it is an OOTB language feature of TypeScript. > React is full of magic syntax that looks like functions, but e.g. you can't call them inside an if statement They look like function calls, because they are. They're not "magic syntax", and in fact, those rules are explicitly because theres no way around that without implementing special syntax | |
| ▲ | threatofrain 3 hours ago | parent | prev | next [-] | | Everything has compilers now and we definitely want to go that direction. The no build people aren’t close to building any popular consensus, like not close at all. Even plain JS is compile heavy because browsers are just compile targets. | | |
| ▲ | recursive 10 minutes ago | parent [-] | | > Even plain JS is compile heavy because browsers are just compile targets. No. Plain JS requires no compilation. |
| |
| ▲ | TomaszZielinski 3 hours ago | parent | prev | next [-] | | I can’t recall a single time where I would want to put JSX in an „if” statement.. In fact I can’t recall a single time where I would want to use JSX in a different context than the return value of a render phase. So from my personal experience the things you mentioned are non-issues in practice. Do you have a different experience? | | | |
| ▲ | bastawhiz 5 hours ago | parent | prev | next [-] | | JSX isn't and hasn't even been necessary to use React. The first version of my company's site didn't have a build step and called createElement manually. And in the decade I've been writing for React, I've never used the React compiler. But saying that it's proof that it's not JavaScript it's like saying that V8 is proof that JavaScript is too complicated because otherwise it would be fast enough not to need a JIT. And all those rules? You don't have to follow them either. Use class components. They're still there, and they work fine. | | |
| ▲ | michaelcampbell an hour ago | parent [-] | | If you also have experience using JSX in a React app, I'd love to hear any opinions/experiences you have with doing the JSX style vs createElement() style coding. I understand how they map to each other but I've only done JSX. That said, I'm old so calling functions all over the place is in my wheelhouse, and I'd love to hear from folks who have done both. |
| |
| ▲ | gloosx 7 hours ago | parent | prev | next [-] | | JSX is just a syntax extension to JS, and it's not even required to create a React app. React "compiler" is in fact a transpiler, which is a very common thing in JS. >React is full of magic syntax that looks like functions Full of magic syntax meaning 5 straightforward hooks? Surely they are not true free-form JavaScript, but at least the syntax itself is not turned into a DSL | | |
| ▲ | patates 6 hours ago | parent | next [-] | | Nitpick: React compiler is not a transpiler. JSX needs to be transpiled, and that's usually done by TS compiler. React compiler is another optional thing on top that's relatively very recent. https://react.dev/learn/react-compiler/introduction#what-doe... | | |
| ▲ | recursive 7 minutes ago | parent [-] | | All compilers translate one language to another language. Historically compilers targeted lower-abstraction languages than the source language. "Transpiler" is a compiler whose input and output abstraction levels are similar. The React cinematic universe has a habit of repurposing existing terminology, but they're both transpilers, to the extent that "transpiler" is even a word. |
| |
| ▲ | sensanaty 7 hours ago | parent | prev [-] | | > 5 straightforward hooks `useEffect` is straightforward? Cloudflare recently (like, literally 4 days ago)[1] had a pretty big outage because of the improper use of `useEffect` (surprise, surprise, it was the dependency array), a hook so infamous if you search "When should I use `useEffect`" you'll get approximately 9 trillion hits, with nearly all of them telling you something different, including Dan Abramov himself having to chip in with multiple blog posts telling people to NOT use it because of how much of a dumpster fire of a API it is. [1] https://blog.cloudflare.com/deep-dive-into-cloudflares-sept-... | | |
| ▲ | gloosx 7 hours ago | parent | next [-] | | Well, that is really embarrassing for Cloudflare... A recursion in a side-effect via dependencies is a rookie mistake, it's hard to imagine it could slip into production with a proper due process. Maybe they should stop vibe-coding and deploying things to production without any tests or review? | | |
| ▲ | sensanaty 7 hours ago | parent | next [-] | | If after nearly a decade swarms of people are still making the exact same mistakes with how they use a specific method exposed by the library, then the problem isn't with the hundreds/thousands of people making the mistake, the design of the method is broken. This type of issue simply does not exist in Vue or Svelte even if people abuse watchers (which I've anecdotally noticed tends to happen from React devs writing Vue code). Also I just want to point out again that Dan Abramov had to write an insanely long guide to using useEffect [1]. This piece is around 10k words explaining in-depth how useEffect works. That is insane for one of the fundamental, core methods exposed by a library. [1] https://overreacted.io/a-complete-guide-to-useeffect/ | | |
| ▲ | 24 minutes ago | parent | next [-] | | [deleted] | |
| ▲ | gloosx 3 hours ago | parent | prev | next [-] | | You know for thousands of years people are still stepping on rake, the spikey part. And they get hit in their foreheads. The rake is lever by design, but I wouldn't say the problem is the rake. | | |
| ▲ | recursive 5 minutes ago | parent [-] | | I've spent more hours using rakes than `useEffect()`, but I've only had the problem with one of them. |
| |
| ▲ | 6 hours ago | parent | prev [-] | | [deleted] |
| |
| ▲ | WickyNilliams 6 hours ago | parent | prev | next [-] | | Disagree about it being a rookie mistake. In the simple case, yes. But consider data used by an effect could travel all the way from root to the max depth of your tree with any component along the way modifying it, potentially introducing unstable references. Maybe it worked when you tested. But later someone introduced a new component anywhere between data source and effect which modified the data before passing it on. That component may have used useMemo. So it looks ok, but it over fires. You become reliant on all your ancestors doing the right thing, in every situation, forevermore. One mistake and unstable references cascade everywhere. The surface for introducing errors is huge, esp in a large, complex codebase. And we have no way to guarantee a stable reference. | | |
| ▲ | gloosx 6 hours ago | parent [-] | | >But consider data modified This is why we never modify data but create new data. Data must be immutable. Strictly typed. Always in the form it is expected to be. Otherwise - crash immediatelly. >But later someone introduced This is why we write integration tests. Introducing anything without tests is only guesswork. | | |
| ▲ | WickyNilliams 6 hours ago | parent [-] | | Sorry I should have been more precise. I don't mean mutation, but taking the data and producing a new (potentially unstable) reference to pass on. Mutating data in react results in under not over firing. It is practically impossible to have full coverage of all code paths in integration tests, since there is a combinatorial explosion of paths. In a case where you have 3 components each with 3 paths you have 27 unique paths. And no app is that simple in practice. It gets out of hand quickly. |
|
| |
| ▲ | TomaszZielinski 3 hours ago | parent | prev | next [-] | | As a rookie with gray hair I completely agree :) | |
| ▲ | 5 hours ago | parent | prev [-] | | [deleted] |
| |
| ▲ | patates 6 hours ago | parent | prev [-] | | Javascript has warts, React has warts, Svelte has warts, Python has warts... It's easy to shoot yourself in the foot in any tech - it's leaky abstractions all the way down after all. useEffect usage needs to die, yes. I don't think it's a case against React, given its age. Otherwise, using React is straightforward. I started coding in it without reading any docs. As someone who used Dojo, prototype, ext.js, jQuery (+UI), Backbone.js, knockout (still has a special place), Mithril, the classic angular, vue (2), svelte, Marko and even Solid (I'm not totally sold on signals), React is the most straightforward by a mile. Is it the most performant? Hell no. Is it the one with the least gotchas/warts? Nope. Concise? A giant no. Batteries included? It depends on what you're looking for... But I can just be productive with it, and it makes sense. | | |
| ▲ | thedelanyo 6 hours ago | parent [-] | | A child who hasn't tasted other mom's food always say, my mom is the best cook in the world. You saying you can be productive in react is just ironic. I just read it as, I can be employable using React. | | |
| ▲ | patates 6 hours ago | parent [-] | | My brain does this sometimes, sorry :) I meant to say, "I can just be productive immediately in React". Not going to edit though. edit: also about the moms cooking analogy... With many of those libs/frameworks, I have much more experience with than react. | | |
|
|
|
| |
| ▲ | unconed an hour ago | parent | prev | next [-] | | >The semantics of React code are very different to imperative straight line code. Yes and all you have to do is learn why those semantics exist in order to do react well. Unfortunately too many programmers still think they can just mimic other code to figure it out. | |
| ▲ | lerp-io 7 hours ago | parent | prev [-] | | um....react is literally js and its not a language, you can write react with or without jsx which is just syntax sugar to make it look more like html. | | |
| ▲ | burnerzzzzz 6 hours ago | parent [-] | | “syntax sugar” means its a new language. It has a new syntax. | | |
| ▲ | rkomorn 6 hours ago | parent | next [-] | | This is the first time I've seen someone argue that adding syntactic sugar means creating a new language. | | |
| ▲ | bryanrasmussen 5 hours ago | parent [-] | | it really depends on how much syntactic sugar you add. You could go back 13 years, show somebody some JSX and ask them what language they think it is and nobody would be well that's obviously JavaScript with a bit of sugar on top. | | |
| ▲ | rkomorn 5 hours ago | parent [-] | | Sure, if I'd been replying to a comment that had anything resembling nuance, that would be applicable. It did not. |
|
| |
| ▲ | theshrike79 5 hours ago | parent | prev [-] | | So Python with type definitions (syntax sugar) is a new language? |
|
|
|
|
| ▲ | motorest 4 hours ago | parent | prev | next [-] |
| > React isn’t just "winning by default" It's winning because at the core it's just JavaScript function composition. A component is a function, conditionals are `if (...) { ... } else { ... }`, loops are `map()`. JSX is just sugar for function calls. I agree with JSX, and function components are nice, but React is most definitely not just function composition. Hooks add state and introduce life cycle events that take components way beyond stateless territory, to the point that it would be far easier to reason about them if they were class components with properties and decorators and handlers invocable through inversion of control. |
| |
| ▲ | cjonas 2 hours ago | parent [-] | | So basically react class components? It definitely was not easier in those days. When your just using vanilla react, I've never had a problem with hooks being that hard to reason about. Once you add in SSR, routers, query caching frameworks, etc the "lifecycle & state" starts to get confusing. This is mostly a problem with the additional complexity of these frameworks (nextjs, tanstack) and not react at its core. Building an app with just react (and maybe redux) feels so simple and natural once you learn the paradigm. | | |
| ▲ | the_gipsy an hour ago | parent [-] | | But you cannot really develop anything meaningful without adding frameworks. I guess redux solves both "state" and "messages" at once, that's good. But what you work with then is not "vanilla react" at all. I don't even think "vanilla react" can really exist, beyond toy examples. You either use frameworks or write them yourself (worse). | | |
| ▲ | cjonas an hour ago | parent [-] | | > But you cannot really develop anything meaningful without adding frameworks. You can develop extremely powerful web-apps using just React + Redux. Once you need to start dealing with SSR for SEO & server side caching, data preloading, hydration, etc... things get complex. But honestly that's because those concepts are inherently complex and that complexity can only be reduced so far. Another problem is they get baked into these framework as the "default" and often over utilized when they aren't actually needed. |
|
|
|
|
| ▲ | azangru 8 minutes ago | parent | prev | next [-] |
| > React isn’t just "winning by default" It's winning because at the core it's just JavaScript function composition. This might be just a rationalization. React might be "winning" (whatever that means), because it was the first proper component-based library, when its competitors (Backbone, Angular, Ember) were large, slow, and clumsy, and still struggling with the concept. Plus, developers back then were easily impressed by the word "Facebook", which meant a large tech company that probably knew what it was doing, and served as a guarantee of good quality. So it had a tremendous head start and good marketing. If Vue, Svelte, Solid, or Lit were there first, who knows if React would be "winning" now. |
|
| ▲ | librasteve 7 minutes ago | parent | prev | next [-] |
| HTMX is the antidote to React and is allowing many green shoots to show through - my favourite is https://harcstack.org … but there are many alternates in many server side languages (disclosure: i am the author) |
|
| ▲ | ojr 6 hours ago | parent | prev | next [-] |
| Thats why it won over the more popular Angular 1 at the time. Angular was introducing directives as a new way to handle dependencies, React chose to stay close to the new ES6 syntax with imports, of course I was going to chose the language that was closer to ES6. I have a feeling React will be closer to the EcmaScript/Javascript standard than Svelte in the future as well ES7/ES8/ES9. Also React Native and React is very easy with LLMs. I am able to build cross platform apps with feature parity which is important because some of us need to make programs for the most popular form factor, mobile, instead of a desktop website. |
|
| ▲ | WickyNilliams 7 hours ago | parent | prev | next [-] |
| Hooks are very much not normal functions though. They are a new "colour" of function much like async functions - they can only be called in components or other hooks, they cannot be called conditionally, cannot be called in loops etc. The so-called "rules of hooks" (To get ahead of the common objection: of course it's still JavaScript by virtue of being implemented in JavaScript. But so are Svelte, Vue et all) |
| |
| ▲ | patates 6 hours ago | parent | next [-] | | I really don't understand this colored functions debate. Async functions are just functions that return Promise<T> instead of T. You can use them in a non-async function but you must then switch to callbacks, because you hold a promise. I don't get how this is confusing, unless you define the whole concept of concurrency in a single thread that runs your UI as well confusing. Hooks are functions that need to be called before early returning, in a function that provides a context for them. They are also just Javascript, they can be implemented with no build tools. | | |
| ▲ | WickyNilliams 6 hours ago | parent [-] | | It's not confusing. It's an observation on their nature. The colouring isn't specific to promises, or even async/await. It applies to continuation style callbacks too. If you haven't, I recommend reading the (original?) article https://journal.stuffwithstuff.com/2015/02/01/what-color-is-... | | |
| ▲ | patates 6 hours ago | parent [-] | | I read the original article and many surrounding discussions & follow-up articles. Not confusion perhaps, but many see it as friction, including the complaints from the original article. From where I'm looking at, it's just a side effect of dealing with concurrency with no threads, what the article also mentions. So, you know, it is what it is, at the end? Now we have people coming up with different definitions of color (react hooks, in your case) and complaining that it's bad? This is like when you are doing embedded programming, holding the API functions you need to call in a special sequence to the same standard as people writing their own DSLs with templates. | | |
| ▲ | the_gipsy an hour ago | parent | next [-] | | The complaint is that it's not just "function composition" (per GP) at all anymore. You're dealing with "component lifecycles". Composition doesn't really work out with hooks, for reference see any non-toy React codebase. | | |
| ▲ | patates 41 minutes ago | parent [-] | | It's like dealing with event handler registrations. You cannot compose those too, as they are "hooks" for when a specific event occurs. Hook definitions can be a composition of reusable functions and other hooks, like any event handlers (e => filterKeys('cmd+s, ctrl+s', preventDefault(e)).then(save)). It's possible to break this anology (you can register an event handler in an if branch) but I hope it gets the point across. |
| |
| ▲ | WickyNilliams 5 hours ago | parent | prev [-] | | I'm not complaining it's bad per se. As I said, it's an observation on their nature. I would not say it's a different definition of colour. I am somewhat contorting the original definition in the article, but if you compare characteristics listed, many/most of them apply to hooks also |
|
|
| |
| ▲ | gloosx 7 hours ago | parent | prev [-] | | Surely they are not normal JavaScript functions, but at least the syntax itself is not turned into a DSL like we see it in Svelte or Vue. That is the main difference. | | |
| ▲ | WickyNilliams 7 hours ago | parent | next [-] | | Yeah I get it. I don't think the "Just JavaScript" label can be applied to react anymore. It held in a class-based world. But it's not true post hooks. I always hated templating languages > Greenspun's {{rules.length | ordinal}} rule: > Any sufficiently complicated templating language contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of the host language But after working with Vue for a 18 months and expecting to hate it, I actually very much enjoyed it. The biggest downside is strictly one component per file. Edit: in case I've come across as some kind of react hater, I was an early adopter and still use it professionally to this day | | |
| ▲ | sensanaty 7 hours ago | parent [-] | | > Any sufficiently complicated templating language contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of the host language Agreed, and Vue does it right exactly because they don't let you do complex things in the template. You can use ternaries in a pinch, but `computed`s exist so there isn't even a reason to do stuff like that. There's like... 10? directives that you can use and they are extremely obvious as to what they're doing, and the handlebar syntax itself is extremely limited and doesn't let you do any crazy stuff with it. | | |
| ▲ | WickyNilliams 7 hours ago | parent [-] | | Yeah I was surprised, how little I felt hampered by its templating language. With things like handlebars and Jinja you often hit a wall like "how the hell do I express this in this language?", but never experienced it with vue. Aside: I wish other frameworks would steal Vue's event modifiers. Doing things like `@click.prevent` or `@keyup.prevent.down` is so nice |
|
| |
| ▲ | hasanhaja 7 hours ago | parent | prev | next [-] | | Syntactical preferences are subjective though and are prone to familiarity bias. I started my webdev career with React so I'm really familiar with JSX and like it, but that alone isn't enough to make engineering decisions. I think semantics could be a more objective way to assess the DX of frameworks because you can have/add a syntactic layer on top that suits your preferences [1]. Semantics would be things like rules of hooks, footguns of `useEffect`, component level reactivity rather than fine-grained reactivity, etc. The high level outcome of this would be being able to answer the following question: "How likely is it that this framework will put me in the pit of success with minimal overhead?" [1] https://vuejs.org/guide/extras/render-function.html#jsx-tsx | |
| ▲ | thedelanyo 6 hours ago | parent | prev | next [-] | | I can create a .svelte file and I can just write only just hmtl - prolly a block of texts within a p tag. With jsx, I don't think it's possible - I need to return it. So even if Svelte is a DSL, to me it feels closer to web standard and jsx | |
| ▲ | baxuz 6 hours ago | parent | prev [-] | | Which is arguably worse, because syntax comes with expectations. The way React (and JSX by extension) works is effectively a bunch of overloaded macros, that depends on the pragma used. And god help you if you want to mix component level code inside React-land and "vanilla". They had to add 3 new hooks over the last 5 years to try and alleviate those issues, all while gaslighting the community and tool authors that the were "holding it wrong". SolidJS is far better when it comes to how well it follows expectations, and how well it integrates. |
|
|
|
| ▲ | magnio 6 hours ago | parent | prev | next [-] |
| Man, I am glad I don't have to work with any developers for whom having to write "className" (which has been in the DOM standard since 2000) over "class" is a deal-breaker. |
|
| ▲ | hbrn 31 minutes ago | parent | prev | next [-] |
| > React feels natural because it never asks you to stop writing JavaScript I want to increment some counter on the webpage. Which approach feels natural? increment = () => {
this.setState((prevState) => ({ count: prevState.count + 1 }));
};
const increment = () => setCount((count) => count + 1);
function increment() {
count += 1;
}
No one wakes up saying "please let me mutate simple state with function calls". |
|
| ▲ | bobbylarrybobby 2 hours ago | parent | prev | next [-] |
| On the other hand, how do you write a function in a react component that retains its identity between renders (to pass as a prop to a child and not have the child re-render when it changes)? You can't — you need useCallback. Meanwhile in svelte you just... write a function. They each have their own quirks. Personally I'd rather write language specific if/else (obvious, can't get it wrong) than have to remember to reactify my functions if I want to avoid subtle performance issues. |
|
| ▲ | KuhlMensch 7 hours ago | parent | prev | next [-] |
| Hard agree. I've used xml directives before, all the way back to Macromedia Flex (which I believe borrowed form something in the Java space, which probably borrowed from something else). I'll likely NEVER use anything that doesn't let me run JSX. My personal preference is for complexity at the start of the render pipeline (e.g. in state) or at the end (e.g, in JSX). So I personally dislike complex hooks composition, but I can live with it. (My) teams seem to like it. I'd rather have boilerplate of redux, or redux sagas - or a S.O.L.I.D framework + scaffolding tools, and turn the composition of logic part of my brain off. But the context switch to maintaining scaffolding tools is perhaps a bit of a jump. As an aside: I'm shocked to see Yeoman largely diminished in activity, and Hygen (https://github.com/jondot/hygen) not getting anywhere near enough love as it deserves etc. Perhaps there is some, first-class macro or meta programming or combination of the two that is missing. Or maybe its hard to invest in tools you can't necessarily take from job to job - as scaffolding tools are capturing opinion. |
| |
| ▲ | mexicocitinluez 4 hours ago | parent [-] | | When I first saw JSX, I immediately thought I'd hate it. Then I jumped boat to React after years with AngularJs/Angular 2+ after hooks and functional components came in and to this day I still enjoy writing React. And I love JSx. |
|
|
| ▲ | JimmaDaRustla 29 minutes ago | parent | prev | next [-] |
| I don't understand how this comment is the top, because it makes no sense. No one writing markup says "Damn, I wish I could write this inline with my javascript." Have you even seen a react component before? People writing javascript containing the markup which, in turn, contains more inline javascript statements for conditional rendering. No logical person would argue "this is better than {#if}{:else}{/if}". |
|
| ▲ | vbezhenar 5 hours ago | parent | prev | next [-] |
| It looks like simple JavaScript. However hooks are magic, so it's no longer simple JavaScript with simple mental model. It's completely different language. |
|
| ▲ | simianwords 7 hours ago | parent | prev | next [-] |
| Clear difference between a library approach and a framework approach. react looks like a library but svelte and tbh angular also look like a framework. As devs we are more comfortable with libraries unless framework offers enough value. |
|
| ▲ | thedelanyo 7 hours ago | parent | prev | next [-] |
| Sure this is js <>
// React code here
<> |
| |
|
| ▲ | sensanaty 7 hours ago | parent | prev | next [-] |
| Sorry, but I'll take Vue's or Svelte's (I prefer Vue's) DSLs over shit like `className` or sticking complex rendering logic in the HTML/template with unreadable `.map`s or God forbid nested ternaries, which is not a rare sight in React codebases. For my brain, seeing a bunch of `v-for`s is a lot clearer as to what's going to ultimately render than seeing a bunch of `map`s is going to render. Also calling it "just JavaScript" might've been true in the Class component days, but in this frankenstein "functional" component paradigm we're at today it's far from the truth. I mean, it's not even a JS file, it's a JSX file for starters. At the end of the day the whole JSX vs HTML-DSL thing comes down to a personal preference, and I doubt it's had much to contribute in terms of the success of the various frameworks. I know plenty of people working with React that despise JSX, and I know plenty of people working happily with Vue or Svelte that hate the DSL for templates. |
|
| ▲ | theknarf 4 hours ago | parent | prev | next [-] |
| Both SolidJs and Qwik keeps the JSX syntax! |
|
| ▲ | mattgreenrocks 5 hours ago | parent | prev | next [-] |
| Please. Let’s get real about the biggest issue with Svelte/Vue/Solid: it wasn’t written by Meta, and had no chance at the clout game that is essential for mindshare. (Not saying React is bad, just that DSLs impeding adoption rings hollow in light of Tailwind/JSX.) |
| |
|
| ▲ | faangguyindia 5 hours ago | parent | prev | next [-] |
| off topic but react code is hard for LLM to edit for some reason compared to other like VueJS |
|
| ▲ | baxuz 6 hours ago | parent | prev | next [-] |
| > It's winning because at the core it's just JavaScript function composition. Except it's not. It has a bunch of footguns and implicit behaviours that make no sense unless you're well-versed in the internals of React. See:
https://macwright.com/2024/09/19/the-extra-rules-of-hooks https://www.schiener.io/2024-03-03/react-closures And JSX by itself is already a DSL, which drastically changes how it works based on the pragma used. JSX for SolidJS, Preact, Inferno or any other framework has completely different internals. |
|
| ▲ | nsonha 8 hours ago | parent | prev | next [-] |
| > winning because at the core it's just JavaScript function composition and now it's failing for the same exact reason, a pseudo "just js function" dsl (hooks) and all the magics enabled by special "compilers" and toolchain. |
|
| ▲ | mvdtnz 5 hours ago | parent | prev | next [-] |
| I feel like you must have learned JavaScript and React concurrently to have a belief like this. |
| |
| ▲ | gloosx 5 hours ago | parent [-] | | Nah, I started with vanilla, then jQuery, then finally learned React. |
|
|
| ▲ | jmull 3 hours ago | parent | prev [-] |
| ...At a logical level, |