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
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.
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.
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?)
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
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.componentDidMount
,componentWillUnmount
, which is usually an error-prone process.Would anyone else share more reasons? (or spot any mistakes I have?)
Thanks a lot for this helpful explanation.
You're welcome.
Enjoy React with 🎣