Hey 👋 what do you think about Compound Components in React? Do you have a favourite design pattern? Let me know! 👇
@outbacklife20253 жыл бұрын
i make them on 8 different monitors
@adammescher4 жыл бұрын
As I have stumbled down the Compound Components rabbit hole, this was exactly what I needed -- all of the pieces assembled in real-time narrated by someone who is capable. Thank you for your time and effort making this.
@CognitiveSurge4 жыл бұрын
You are welcome Adam!
@martinfoakes47754 жыл бұрын
Good stuff! That use of the index.js file in your components folder is one of those things where, as soon as I saw it, I immediately wondered why I had never done that before
@CognitiveSurge4 жыл бұрын
I had that same lightbulb moment happen to me a few months back 😆
@jasonmiani81084 жыл бұрын
^^
@keduslejiyared87014 жыл бұрын
I learnt a lot from this video and I'm not even halfway through! Thank you, Karl.
@CognitiveSurge4 жыл бұрын
Glad it was helpful!
@lakshyamunjal56084 жыл бұрын
I have never heard of Compound components before and after watching this video, I totally understand it. Thanks Karl!
@CognitiveSurge4 жыл бұрын
Happy to help!
@cv37874 жыл бұрын
I tried to rewrite this in TypeScript but was unsuccessful. How do I write Card.Body etc without getting errors by TS?
@danva92733 жыл бұрын
This was my first React mini-project, simple yet informative, thanks!
@CognitiveSurge3 жыл бұрын
Great to hear!
@DarrylHebbes10 ай бұрын
Compound Components basically start at 9:10 mark
@kostya33125 жыл бұрын
Thanks for useful tutorial. One note - className prop of Card component is overrided by className prop of Container component (through restProps destructuring). There is same issue for other components too. As a result there will not be classes 'card', 'card__body' and others in the final markup.
@CognitiveSurge5 жыл бұрын
Ahh yes, my bad. If you switch from 'className' to 'classes' when passing down additional classnames, it should retain the set class that is set under the hood and allow you to additionally add anything on. Great spot my friend, will update the repo with 'classes' for the example on Card.
@LumbreraEnMiCamino3 жыл бұрын
how can do this with React and typescript? including props and interfaces
@CognitiveSurge2 жыл бұрын
Will show in a future video
@rofazayn5 жыл бұрын
After watching your video I realized how stupid the way I am using styled-components is 😂 Thanks Karl, great content as always.
@CognitiveSurge5 жыл бұрын
Don’t worry, I did the exact same thing many times 😂 at first I wasn’t a fan because I wasn’t using them correctly, now I understand them, I love them 😀 thanks dude 🙌
@juliuscecilia60054 жыл бұрын
Learned so much from this! Beginning to use this in my projects! Thank you so much! :D
@CognitiveSurge4 жыл бұрын
Great to hear!
@outbacklife20253 жыл бұрын
sir instead of the joker image can i display a image of what th euser uploaded for like a apartment are room search?
@CognitiveSurge2 жыл бұрын
Yep, can do
@govindkothari79894 жыл бұрын
@Karl Hadwen i have one dought like for representing an image we have to use img tag so like how card.Image is replacing the img tag Or card.Image will convert to img tag depending upon what props we passed on card.Image
@CognitiveSurge4 жыл бұрын
I'm not too sure what you mean?
@VitorBoccio3 жыл бұрын
why do u use the classname library? I mean, Styled components already create dynamic classes names and if you import from 'styled-components/macro' the class name will contain your component name as well.
@CognitiveSurge3 жыл бұрын
I was being lazy, you can use that or just use export function classNames(...classes) { return classes.filter(Boolean).join(' '); }
@lukaszwalczak38143 жыл бұрын
Can someone please explain dot notation? What's the point of doing it?
@CognitiveSurge3 жыл бұрын
It's a marmite pattern, some find it useful and others not so much. I was just experimenting with things mainly when researching the pattern
@lukaszwalczak38143 жыл бұрын
@@CognitiveSurge I like marmite. Especially on toasts :). I think my question should've been 'How does dot notation translate to JS world? Is Card.Title like a property of the Card component? Like in objects - object.property?' Cheers, mate.
@tallahondro4 жыл бұрын
Loved the video, still not sure how the dot notation is working under the hood for something like Card.Image = f(n). Do functions take on the same behavior as objects in JS? You are essentially declaring a function onto another function?
@CognitiveSurge4 жыл бұрын
Yep, pretty much that! Give this a read, it should help: blog.bitsrc.io/the-chronicles-of-javascript-objects-2d6b9205cd66#:~:text=Almost%20everything%20in%20JavaScript%20is,primitive%20values%20or%20primitive%20types. - apologies for the slow responsive!
@well.83954 жыл бұрын
In your styled/Card.js file - Line 42, there's an error. className={(classNames('card__image'), classes)} should be className={classNames('card__image', classes)}
@CognitiveSurge4 жыл бұрын
Oops xD
@user-uh3zr7mo4i5 жыл бұрын
I really needed this, thanks Karl
@CognitiveSurge4 жыл бұрын
Glad I could help :)
@Skia_5 жыл бұрын
I'm loving the accent ;D Greetings from Lebanon.
@CognitiveSurge5 жыл бұрын
🤣 thanks dude! Greetings from Leeds, UK! I hope all is going great and you have an awesome 2020!
@baldmannnnn2 жыл бұрын
Hi Karl! I'm able to understand and use compound component pattern on my react projects because of this tutorial. But now I'm trying to implement it on typescript and I'm having all sorts of problems. Can you make a video about compound component pattern with styled components using typescript?
@CognitiveSurge2 жыл бұрын
Will take a look!
@buntybru31062 жыл бұрын
Thanks Karl
@CognitiveSurge2 жыл бұрын
Np!
@emaxix74 жыл бұрын
Great video! What's the name of the font-family you use on VSCode?
@CognitiveSurge4 жыл бұрын
All in my setup video :)
@Abhishek-dp5tc4 жыл бұрын
font-smooth is unknown property.....it shows in codesandbox
@CognitiveSurge4 жыл бұрын
There' are a few compatibility issues at the moment with font-smooth but they should be resolved in the future hopefully
@saisharathsamala59223 жыл бұрын
Very good useful video 👌
@CognitiveSurge3 жыл бұрын
Thanks a lot!
@inayatcassambai4694 жыл бұрын
I feel like there isn't a major difference between the 2 examples you showed at the start of the video. I personally would prefer to go with the example on the left. Yes i would have to create individual component files for each element, but this way, each component would be encapsulated within it's own file which is something i prefer. The method you demonstrated has all the component logic in one file which makes it feel cluttered to me. But again, these are just opinions and everyone has their own preferred way of working! I could still have a folder in the components directory called cards. And then have all the relevant card components live in this folder accompanied by a index.js file. Then i can use this to import only the components i need like so: import {CardTitle, CardBody} from './components/cards'
@CognitiveSurge4 жыл бұрын
You make a good point. I did use this method of design in the Netflix video I recently did, but on a larger scale, I'm not sure I like compound components, I'm on the fence. I'm half way through an Instagram clone and went back to just regular components and I think I'm actually enjoying using them more.
@inayatcassambai4694 жыл бұрын
@@CognitiveSurge You may find this article interesting! epicreact.dev/soul-crushing-components/
@CognitiveSurge4 жыл бұрын
@@inayatcassambai469 Will read that in the morning. Thanks for commenting btw, these type of discussions are one of the reasons I created this channel!
@amirnoorani50174 жыл бұрын
Extremely helpful!
@CognitiveSurge4 жыл бұрын
Thank you!
@omarhassan25484 жыл бұрын
This is another great video Thanks Broo
@CognitiveSurge4 жыл бұрын
Thanks Omar!
@ManuelNyC774 жыл бұрын
I'm sorry, I can't understand why you use the functions in the components, as an example, Card.Body = function CardBody, I can't get why you use the function CardBody :/ can someone help me?
@CognitiveSurge4 жыл бұрын
I use it to wrap all the other components inside and apply styles to it
@zourdy6973 жыл бұрын
mate would be great if you create content about advanced react patterns or context.
@CognitiveSurge3 жыл бұрын
Definitely! Those are quicker to do too xD
@MaganDesigns3 жыл бұрын
My portfolio tanks you a million.
@CognitiveSurge3 жыл бұрын
haha
@iali10465 жыл бұрын
Awesome 👏
@merveillevaneck59064 жыл бұрын
im failing to see what exactly the implementation benefit is to this approach on this specific example? can anyone maybe help my stupid ass see the benefit?
@CognitiveSurge4 жыл бұрын
This comment did make me lol...it's basically just a pattern that's used in design libraries, so for example if you had 10 people using one of your comments but they wanted only certain aspects, they could just pull in the one component and then get the stuff they need, e.g. - and use it as it, you can do the same with individual components but it becomes a bit tedious. But all in in, it's just a pattern and up to the user to decide which they like best :) hope that helps!
@Abhishek-dp5tc4 жыл бұрын
make more videos on styling in React, Also you can make on Tabs, Accordion(components)
@CognitiveSurge4 жыл бұрын
Tailwind videos coming but also much more CSS videos!
@Max142114 жыл бұрын
@@CognitiveSurge Aw man that's going to be dope im looking forward to it :D. Just to pick your brain for a second, I heard the some of the team-members who where part of tailwind created ThemeUI as a sort of successor to tailwind. I was wondering, on a production level, do you think that tools like Tailwind will just become a sort of passing fad and people will move into more barebones tools like ThemeUI or do you think that startups and mid-size companies will prefer heavier CSS frameworks going forward and that tailwind is more for smaller projects? P.S Just wondering your thoughts, its the tech world and no one predicts it right LOL so i'm not going to hold you to perfection or anything just your gut reaction to a random question lol. Cheers for all the videos :)
@EcklerV4 жыл бұрын
Can't you just write like this? Card.Title = Title. Isn't it the same? I mean styled component basically takes it's props and pass them down or am I mistaken? Do you do it just to add classname ?
@CognitiveSurge4 жыл бұрын
Yep, I did it just to add classname, but now I don't use classNames at all. I've removed it completely and handle all my styling via a styled component
@EcklerV4 жыл бұрын
@@CognitiveSurge Could you please share a chunk of code that illustrates your new approach? I'm new to styled components and trying to figure out the best way to use them. Thanks in advance!
@BrunoWinck5 жыл бұрын
Another great one, keep sharing :)
@CognitiveSurge5 жыл бұрын
Thanks Bruno! Hope you're well and happy new year!
@avneet122842 жыл бұрын
Didn't realize that adding a dot makes them children. WOW ! 😮
@CognitiveSurge2 жыл бұрын
:)
@abiakhil694 жыл бұрын
Awesome content
@CognitiveSurge4 жыл бұрын
Thanks dude
@unknownman14 жыл бұрын
Hey Karl sorry to say this, but didn't understand the concept clearly. I came here because in Netflix tutorial you've used styled components.
@unknownman14 жыл бұрын
Alright, I read the docs and watched the video again and understood the concept now. Thanks Karl.
@CognitiveSurge4 жыл бұрын
Glad you understood it dude! I'm moving or I'd have been able to help more!