Hacker News new | past | comments | ask | show | jobs | submit login
React Internals (2017) (mattgreer.dev)
86 points by ofou on Oct 12, 2021 | hide | past | favorite | 25 comments



This one was updated after fiber and hooks: https://pomb.us/build-your-own-react/


That was a really pleasant UX. Well done.


Thanks for sharing!


Great work!


(2017) or React 15.3 Internals


This is pretty interesting, how much has since 2017? Probably the new hooks but other than that?


React 16 brought along new internals:

https://reactjs.org/docs/faq-internals.html


the last React version that feels pragmatic.

The APIs introduced after this are poorly designed in my opinion, the "function as children" context API (and TWO other ways to access context) and hooks


I don't get why hooks were introduced. It's just some magic that doesn't feel like JS.


How long before react updates to doing things the svelte-way?


The biggest strength of React is that it is _just_ a library. You don't need to write JavaScript/TypeScript in a special way (other than limiting side effects, which is not a React-specific challenge).

Svelte is not JavaScript. Svelte is a compiler that significantly changes the way code is executed, despite being superficially quite similar. Samples of code that look like they would be equivalent in JavaScript are not equivalent in Svelte.

This can be good for easily reaching a performant version, but it's also a major drawback.

Reconciling these approaches seems quite difficult--maybe the tsx compiler could begin to recognize some common patterns that can be compiled to simple in-place updates. But it would be brittle, since React is more expressive in that it allows lots of code that _can't_ be straightforwardly transformed into efficient in-place updates.


React is a framework that doesn't want to admit it's a framework. If you follow its recommendations like Hooks, you have to write your JS a "special way" since React owns your component lifecycle.

Put simply, React calls your component, your component does not call React. Your UI code needs to work inside of React, not around it.

The relevant and most upvoted HN article on the difference between libraries and framework is:

https://www.brandons.me/blog/libraries-not-frameworks


Everything that you can do with Hooks can be done with Class components though. Of course Class components also have a lifecycle that is managed by React. But the existence of a managed lifecycle does not make it a framework either.

The article you linked has the answer:

> has it established ways of doing things that are mutually-exclusive with other ways those things might be done?

The answer here is a solid No in the case of React. Nothing is mutually exclusive, because you choose to use Hooks in one component, a Class in another and you can still use React.createElement elsewhere and straight HTML with vanilla JS even somewhere else.


Exactly!


Svelte is pretty much JavaScript. Which samples work in JavaScript but not Svelte?

I would guess that 90%+ of all React written goes through a compile/transpile step in the development process which makes the difference between writing React apps and Svelte apps negligible.

I actually went back to React after using Svelte but I think the compile step makes more sense since you're not delivering the library to the end user.


What made you come back to React?


Mainly the ecosystem and prospect of jobs. There's 0 svelte jobs where I live but lots of React ones. Since Svelte is easy to pick up I'll happily switch back if the opportunity ever arises.


I really like Svelte and want to see it succeed but I think it's more likely that React will somehow adopt innovations from other frameworks and remain dominant.

I'd love to be wrong about this. Especially since I'd rather not use tools from Facebook if possible.

Solidjs is also interesting IMO.


Svelte was the fastest I went from "oh god here we go, another framework" to "this is freaking amazing, why has this not been built already". To your point about avoiding React because of Facebook connections. I will say for all the shit that Facebook has dumped on this planet, releasing React will probably be remembered as one of the better things they did.


That version of React was interesting and popular! The incentive for going through such a series shouldn't be to better use React, but see closely how a generally successful piece of software was made and some of the clever tricks that one might use in their own future projects.


I don't think that it's very likely, simply because that would be too much of a breaking change: React's strength lies in its huge ecosystem, and they'd throw that away by changing the framework's fundamental building blocks.

It's more likely that Facebook will start another framework (or compiler) in parallel. Or simply start using Svelte.


afaik, once an app gets big enough, using a virtual dom actually produces a smaller build than using Svelte's compilation model, and it also places fewer restraints on the ways you can structure your code.

Svelte's model isn't strictly better; like almost everything in programming, it just has it's own set of tradeoffs.

Relevant tweet thread: https://mobile.twitter.com/dan_abramov/status/11354244236689...


Never, because Svelte has you expressing logic as html tag attributes and React lets you just use JavaScript.


componentWillMount()?

This is ancient. Before the pandemic, even.


yeah that's BC (before Covid)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: