For further actions, you may consider blocking this person and/or reporting abuse
Read next
TokenFormer: Rethinking Transformer Scaling with Tokenized Model Parameters
Mike Young -
New Research Breaks Through AI Language Model Safeguards, Exposing Security Risks
Mike Young -
New AI Revolution: Designing a Global Multi-Agent Network with Large Language Models
Mike Young -
The 6 Best Free Tools for Testing Webhook and Callback URLs
Sospeter Mong'are -
Top comments (15)
TL;DR
HoC is like Iron Man Suit.
Tony Stark is a person.
When he puts on an armor, he turns into Iron Man but he is a person inside
but can do more (I mean A LOT more like flying and kicking @$$ and stuff).
Details
Iron Man suit is made up of iron gloves, boots, armor, helmet.
Tony with iron gloves, he can fire lasers,
Tony with iron boots, he can fly,
Tony with armor, he can power up his suit,
Tony with helmet, he can control
See the pattern?
So gloves, and boots, armor, and helmet are like HoCs.
Each one gives him more to do.
Tony with gloves, boots, armor, and helmet turns him into an ironman.
NOTE
This is not gonna work. Iron Man is rated PG-13... ๐
This is a very creative analogy, for a person familiar with HOCs I totally get it. I just worry it might have missed an important detail which might not be that obvious to a newcomer.
HOC is not a component but just a mere function which happens to return a component. ๐งค , ๐ข would rather be the output of the HOC.
When we write โwithCompX(compY)โ, we mean this HOC will wrap compY with CompX.
The examples below are similar in logic, the only difference is that one is done real-time and the other is done statically/by hand.
Thanks Kushan.
I see where my analogy breaks down as I was using each object(gloves, helmet, etc) as a concrete component, not as something that enables Tony to do something.
Dude this will totally work. Toy aisles are lined with Avengers merch.
Thanks, Cat.
LoL, I haven't been to toy stores for years thanks to online shopping sites ๐
Awesome! Thanks!
Say your teacher asks the entire class to paint a portrait of their families in some kind of outdoor setting.
Now, you, being as smart as you are, realize that an outdoor setting would almost always mean a blue sky with the sun shining. And any more specific items like a house, a green backyard, a pool, rainbow, trees, family members etc would have to be drawn on top of the blue, sunny background.
So you decide to help everyone in your class out a little and paint a blue, sunny sky (The HOC). And then you draw copies of it, and distribute them among your peers.
The blue sky painting with the sun is useless on its own, but your friends can draw a lot of fun, interesting scenes on top of it and thus make it meaningful (The component fed to the HOC). And of course they all have erasers to adjust minor details like color boundaries (e.g. where the sky meets the ground).
Of course, your background painting won't work for everyone: some of your classmates might want a night scene or the sun in a different position etc. But that's ok. Because before you began this endeavor you realized that you would end up helping a good number of your friends.
Perfect! Got it! Thanks!
ELI5
I (your teacher) sees that you are a curious one. I first answer what components are. Components are sheets of paper, anything you see around that is Paper is also a component.
I point you towards a printer and say this is an HOC sweetie, go ahead use it. You being a smart 5 year old know how to use a printer. I explain further to the class.
Alex exclaims, "It is still a Component, but it is so much more cuter!"
I love that you used my son's name! :) Thanks!
Sometimes components do similar things to other components (or the "lego blocks" of a website). Rather than repeating code, we wrap the components inside "higher order components".
The higher order component handles the similar task, like say, pulling data from a website, and then sends the data down to the child component. This lets us keep each component responsible for a single thing, like showing comments (child component) or grabbing comments (higher order).
Higher Order Components are the Render Props of 2015 ;)
They are basically functions that take a reference to a component class and return an new component class that does something with the first class.
Redux, for example, uses this to push data from its store into the props of a component.
Hey, Daniela. I'm confused when I saw this "do sth
like I'm five
". I'm not a native speaker, just wonder what it really means.It means to explain something as if I'm a child. Not using technical words. Using words that a child can understand.
Interesting, thanks for your explanation.