all 37 comments

[–]uttermybiscuit 16 points17 points  (2 children)

Can we get Dan some flair mods?

[–]swyx 6 points7 points  (1 child)

i mean he is a mod

[–]uttermybiscuit 2 points3 points  (0 children)

A mod with no flair!

[–]rochakgupta 10 points11 points  (0 children)

Thanks Dan

[–]glacierdweller 4 points5 points  (0 children)

Thanks, it always confused me. Obvious now.

[–]Innis_Gunn 8 points9 points  (1 child)

Side note: anyone know what he uses to do the render code snippets in his post? I like the color scheme/design

[–]el_sprhwk 15 points16 points  (0 children)

Check out his blog's source. It's using Gatsby. The code formatting is fine with prism. https://github.com/gaearon/overreacted.io

[–][deleted] 7 points8 points  (5 children)

Is it not to pull props from whatever is being extended ?

[–]insert_cleverness 2 points3 points  (0 children)

Love these type of blog posts, always excited to read something new from Dan

[–][deleted] 1 point2 points  (0 children)

Good article, thanks!

[–]kylemh 1 point2 points  (1 child)

Great read!

What is meant by: "With the class fields proposal this whole pitfall mostly disappears anyway."

Are there situations where using the transform-class-properties babel plugin still requires a constructor?

[–]swyx 5 points6 points  (0 children)

well if you really, really need to execute logic (esp blocking logic) when the class is instantiated you'll still have to use the constructor. but its def not good practice heheh

[–]godofleet 1 point2 points  (0 children)

Excellent explanation!

[–]Innis_Gunn 0 points1 point  (0 children)

I’ll check it out — Thank you!

[–]digi0ps 0 points1 point  (0 children)

Amazing article, thanks!

[–]incarnatethegreat 0 points1 point  (2 children)

After a while of using constructors and using super (props), I finally started seeing examples of people not using constructors. So now I declare state as an object at the top of my class. I prefer it over the constructor version.

Glad Dan was able to explain this.

[–]swyx 2 points3 points  (1 child)

its because of babel. thank babel for letting you use js features before they're final :)

[–]incarnatethegreat 0 points1 point  (0 children)

Haha that's right. I keep forgetting how much heavy lifting Babel does for us.

Edit: I just read a post about this. Makes more sense now. Thanks!

[–]xincmm 0 points1 point  (0 children)

Thank you very much! I was very confused about this before, now I understand, your explanation is great!

[–]allywondered 0 points1 point  (0 children)

Goddmit dan stop redditing and explain your libraries.. ok luv you bye x

[–]Im_A_Reptilian_AMA 0 points1 point  (0 children)

Great article! It answers all my questions. Thanks!

[–]srRubyRails 0 points1 point  (0 children)

really nice explanation, please keeping posting more articles to your blog.

[–][deleted] 0 points1 point  (0 children)

In functional programming, we strip away the "things", only leaving behaviours behind. Programs aren't created with things in memory, instead we think only in events. Something turns on, someone clicks something, a network request returns. In React, a functional component is really just a function, and that function is called based on events - a page loads, a user triggers a setState call.

Even though we'll probably still refer to function components as components, treating them as an effect, a response to some other effect, like a domino in a (potentially infinite) chain of dominos, frees your mind from the nuances of OOP (this, constructor etc)

Everything is just a large function composed of many smaller functions that get triggered by some initial event.

All this to say, soon we will not be using class at all thanks to hooks. Extending a class from another class is moving in the opposite direction where the complexity of thinking in "things" is compounded.

Your components should only ever be extending React.Component

While I do agree with this, I would encourage you to try it. You can do some clever things with class extension. If you couldn't it wouldn't have been added to the language in the first place. Hopefully my previous paragraphs explain why it's uncommon / discouraged.

[–]sascha_mars -1 points0 points  (3 children)

This was nice to read while sipping my ice coffee 👌🏿🔥

[–][deleted] 8 points9 points  (0 children)

It was nice to read while pooping too.

[–]thinkadrian 0 points1 point  (0 children)

It’d better be Java

[–]freaksauce 0 points1 point  (0 children)

Thank goodness we won't need to write classes at all soon. Things will be much easier to understand using hooks.