DEV Community

Cover image for Learn Public Class Field Syntax by Refactoring a React Component

Learn Public Class Field Syntax by Refactoring a React Component

Angelika Jarosz on May 31, 2019

When you are reading React code, you come across many different ways of doing things that accomplish the same thing. As a beginner this can be an e...
Collapse
 
darrenvong profile image
Darren Vong • Edited

When we use class fields to add methods [...], the class fields are added to the instance itself instead of the prototype.

Interesting, I did not know this before reading your post! For maintainability, I tend to prefer clean code over worrying about micro optimisation details, but I can definitely see this adding performance overhead if lots of these components are needed for an app. I'll certainly bear this in mind when writing future React components!

Collapse
 
jung2x profile image
Jung2x

Agree, quick write & clean code first, optimisation later

Collapse
 
kakakcii profile image
kakakcii

I'd verify that bit of information before "bearing that in mind"

Collapse
 
kakakcii profile image
kakakcii

Coming from a both Java and JavaScript background, I have to say I'm quite confused by the name "public class field". As the name suggests, being a "class field" should means that you should only have "one copy", aka added to prototype. Why it turns out to be the opposite?