Saturday, April 8, 2023

Writing Class components, Higher order components, Render props

 


these two weeks i was learning about these 3 topics : Class components, Hoc, Render props.

was missing these topics because i took an updated react course which teaches about functional components and hooks since they are the standard now a day's , however i knew i needed to grasp these concepts because i may come across with them in a old codebase. 


learning about class components was a bit easier then i was expecting because i already learned about object oriented programming in vanilla JavaScript which uses classes and constructors and the this keyword and super, i practiced it for a while and rendered some small components.


Higher order components was trickier, it took me sometime to grasp it, but at the end its taking a component as an argument and returning that component with added features. its useful for dry, meaning less duplicated code. 


render props role is just like the hoc, its useful for sharing code between react components and helps us to not write the same code again, its takes a function as a value and returns a logic