Why does React Hooks enable writing simpler code? 🎣

twitter logo github logo Updated on ・1 min read

While learning React Hooks I have read a lot about the conceptual decisions of the React team. E.g., they state that React components with React Hooks are easier to write and understand as Class components.

Why do you think writing projects with React Hooks will lead to more understandable and maintainable code?

twitter logo DISCUSS (4)
markdown guide
 

Hooks enables "function component" (FC) to "hook" into React's life cycle methods getting rid of the need to use "class components" (CC).

The reason this makes it more "understanble" & "maintainable" code is

  1. Within FC, you don't neeed this mostly to refer to internal methods, variables thus make the code shorter and less error prone.
    • this in JavaScript is pretty tough to swallow. Less of it to deal with easier to understand.
  2. Hooks makes code shorter (refer to this image comparison as an example).
    • Less boiler plate code required means, less code to maintain, thus easier to maintain and faster to develop.
  3. And also, clean up codes can be co-located without spreading through React life cycle methods such as componentDidMount, componentWillUnmount, which is usually an error-prone process.

Would anyone else share more reasons? (or spot any mistakes I have?)

 
 

Using React Context is less verbose and, thus, much easier to understand and develop.

Classic DEV Post from Mar 29

It’s 2019! Let’s End The Debate On Icon Fonts vs SVG Icons

Icon Fonts vs SVG Icons! This is a debate that shows no signs of abating and is splitting the dev community into two. Here is a detailed comparison of both.

Sebastian Weber profile image
Frontend developer from Germany. Also interested into UX and backend dev.

Hey there reader...

Do you prefer sans serif over serif?

You can change your font preferences in the "misc" section of your settings. ❀️