Live data from Hacker News

Ask HN: How can we make React better?

news.ycombinator.com

21–30 of 68 posts

Re: Ask HN: How can we make React better?

#22
Maybe this is either an uncommon use case or I'm missing an easy way to do it, but when you have a component tree like A->B->C (-> denoting child relation) and A contains most of the state and B contains many (say > 1k) children, and you keep updating state in A which only affects one or a few of C, the diffing process as I understand will check all of C whether they need to be rerendered. So if you update the state super frequently, let's say on mouse movement, you are doing at least O(C) checks just to update one or so C components.

So maybe you can pass forward refs from A to all the C's and then bypass B in the cases you want to directly trigger rerender on the individual affected C components. Is that the way to handle this scenario?

It's pretty late so the above maybe doesn't make sense, but to try to summarize, having a solution for updating deeply nested children without diffing all of the related components to see if they need rerender.

Re: Ask HN: How can we make React better?

#23
post #14

Size. For my use case of a hybrid mobile app where I'd like to render lightweight webviews, the overhead of react is far too great. For this i'll actually reach for Preact instead. Or perhaps even the relatively new Svelte (disappearing) framework.

Thanks for the feedback! We've found that in most cases the components you've built tend to be much larger than React itself, and indeed if we can reduce the size of your components by adding things to React then that is often a good tradeoff for us. However we do try to keep the size down; for example React 16 included a 30% size reduction. When you say "the overhead of react is far too great" are you speaking from…

I'm playing around with react-dom-lite, and frankly it's exactly what I need - I'm getting less worried about IE support by the day, and it drops the bundle size by quite a bit.

I'd love to see React itself ship with options to drop polyfills and old browser support if it helps the bundle size.

Re: Ask HN: How can we make React better?

#25
Align with, improve, and build upon, Web Components specifications, as well as other ongoing W3C standardization efforts. I.e. be stewards of the Web Platform ecosystem.

Promote harmony, cross-compatibility, and longevity in the web development landscape.

Re: Ask HN: How can we make React better?

#27
post #22

Maybe this is either an uncommon use case or I'm missing an easy way to do it, but when you have a component tree like A->B->C (-> denoting child relation) and A contains most of the state and B contains many (say > 1k) children, and you keep updating state in A which only affects one or a few of C, the diffing process as I understand will check all of C whether they need to be rerendered. So if you update the state…

Forgive me if I misunderstand the problem, but is it not sufficient to implement a fast shouldComponentUpdate on C, ideally making C a pure component? The render pass will still do a check for every C whenever B updates, but I would think that strict equality checks would usually be fast enough even for thousands of components every animation frame.

If that’s not fast enough, perhaps it would be faster to directly subscribe each instance of C to its state updates with something like Redux’ connect HOC. I assume that React does something like marking branches of the component tree as dirty and only doing a render pass on the dirty sections, but I could be wrong. If I’m correct, that would give you direct rerenders of the individual deeply nested C instances without rerendering A or B or unchanged C components at all.

Re: Ask HN: How can we make React better?

#28

be more like Vue

Anything in particular you think Vue does better? We'd love to improve.

I do love Vue's single file components for small components. It's a big productivity boost to be able to reason about the different facets of a component together.

Re: Ask HN: How can we make React better?

#29

Eliminate manual typing of PropTypes.

Just completed a chapter on PropTypes. While useful, they seem to be an excessive and tedious. Can't we somehow leverage TypeScript for the model validation instead?

TypeScript, Flow, and ReasonReact all support defining types for props. React PropTypes are completely optional and only give warnings in development, so I you’re using a language or language extension with compile-time type-checking you shouldn’t need PropTypes.

Re: Ask HN: How can we make React better?

#30

be more like Vue

Anything in particular you think Vue does better? We'd love to improve.

I recognize that it's a very different philosophy, but first-class support for interpolated HTML made porting existing applications very easy in Vue.
Post reply on HN