Vincas Stonys
Vincas Stonys
  • 6
  • 109 610
Un-Suck Your React Components - Composable & Compound Components
Learn how to apply component composition to solve prop-drilling and make your components more flexible. Take your components to the next level by using the context API and building Compound Components.
🏁 Final code: stackblitz.com/edit/react-ts-uzanui?file=App.tsx
🌟 Subscribe to my channel and FINALLY learn to build more than just a to-do list with React: www.youtube.com/@vincasstonys
Here's the platform I recommend to learn Web Development online: www.educative.io/explore?aff=Vp6m
For more content:
- Follow me on Twitter VincasStonys
- Read my blog at codefrontend.com
0:00 Intro
0:56 Problem Explanation
2:01 Component Composition
7:20 Adding the Context API
12:56 Compound Components
15:45 Outro
Tech used in this tutorial:
- HTML / CSS
- React.JS
- TypeScript
มุมมอง: 86 456

วีดีโอ

Encrypted Notes App Tutorial for Beginners | React.JS + TypeScript
มุมมอง 8K2 ปีที่แล้ว
Kickstart your web developer's portfolio by building an encrypted notes application. I will guide you through the tutorial step-by-step, beginner-friendly - you only need to know the basics of CSS/HTML and ReactJS. 🔥 After finishing the tutorial, feel free to extend this application with your own design and extra features, then add it to your portfolio. 🌟 Subscribe to my channel and FINALLY lea...
Build Image Preview Feature | React.JS + TypeScript Beginner Tutorial
มุมมอง 2.9K2 ปีที่แล้ว
Learn how to build an image preview with zoom controls using React. Project repo: github.com/vincaslt/youtube-code/tree/main/image-preview 🌟 Subscribe to my channel and FINALLY learn to build more than just a to-do list with React: www.youtube.com/@vincasstonys Here's the platform I recommend to learn Web Development online: www.educative.io/explore?aff=Vp6m For more content: - Follow me on Twi...

ความคิดเห็น

  • @tohirul
    @tohirul 2 หลายเดือนก่อน

    why did you stop making videos?

  • @bhakti214
    @bhakti214 2 หลายเดือนก่อน

    what in the world, it is like a magic to me, gonna deep dive to get a better understanding so I hope i can implement it in my use case. thanks A LOT man!

  • @imornar
    @imornar 3 หลายเดือนก่อน

    Imagine having this dude with his keyboard in your office

  • @patrickudekwe
    @patrickudekwe 3 หลายเดือนก่อน

    Is this for only software developers?

  • @PhilipIsaacs
    @PhilipIsaacs 3 หลายเดือนก่อน

    Excellent Tutorial.

  • @Lemmy4555
    @Lemmy4555 4 หลายเดือนก่อน

    This is a good pattern to use, especially for low level components. prefer slots over props to keep the code of the component easy. Another suggestion i would give is to make the components do as little as possible, whatever you are not sure is not going to be reused most of the times should stay in the parent, i think a common mistake is to pass the options props to a Select component, but the options may be in many format, value-label, value-label-andLotOfOtherStuff, maybe you don't even need the label because you are showing a bunch of icons, also the options may come from an API or may be filterable, and the filtering logic may vary, etc. So just move the handling of the options and the selection of the value in the parent and it will simplify the code of the Select greatly, while the code in the parent would be easy to understand because it will be very specific for that Select.

  • @K.Huynh.
    @K.Huynh. 5 หลายเดือนก่อน

    thank you for sharing!

  • @user-gm3lg8gp3m
    @user-gm3lg8gp3m 5 หลายเดือนก่อน

    Great tip!

  • @shane3744
    @shane3744 5 หลายเดือนก่อน

    This was very helpful and informative! I have a couple of questions if you have time to answer: 1. Why does <ProductCard> use slot props as opposed to only "children" like the compound components? 2. Are there concerns about bundle size when using compound components since you're always importing all of them?

    • @krishna9438
      @krishna9438 3 หลายเดือนก่อน

      old comment but I'm guessing slots restricts the order of components or DOM structure (ie image on top, info in the middle, cta button on the bottom) based on ProductCard's implementation while children have more wiggle room

  • @henriquematias1986
    @henriquematias1986 5 หลายเดือนก่อน

    This is the way to go, sadly jr developers still have issues understanding how context work. We will get there tough ( :

  • @einfacherkerl3279
    @einfacherkerl3279 6 หลายเดือนก่อน

    first time someone wrote react code using a typewriter!

  • @rea_kr
    @rea_kr 6 หลายเดือนก่อน

    I would like to follow over your video from the initial code. I'd like to follow along while watching the video, starting from the initial code. Could you possibly provide the initial code too?

  • @utkarshsinghchouhan8819
    @utkarshsinghchouhan8819 6 หลายเดือนก่อน

    Man I was Just Thinking about the Same Problem for Scalable Components" and The TH-cam Recommended it to me. I am Happy now😊😊

  • @angstrom1058
    @angstrom1058 6 หลายเดือนก่อน

    Great video, Vincas. Thank you.

  • @XDBjoernXD
    @XDBjoernXD 7 หลายเดือนก่อน

    wow, I learned a lot

  • @miettoisdev
    @miettoisdev 7 หลายเดือนก่อน

    you're still using props, those should be children components

  • @toonmystoryanimated.6766
    @toonmystoryanimated.6766 7 หลายเดือนก่อน

    No link

  • @streetjnoun
    @streetjnoun 8 หลายเดือนก่อน

    I wish I saw your video earlier. I just had a live coding interview and had no idea about this principle...

  • @justAbeautifulSoul409
    @justAbeautifulSoul409 9 หลายเดือนก่อน

    for independent calls allsetteled is better than all

  • @Gangbuster74
    @Gangbuster74 9 หลายเดือนก่อน

    but wont it affect performance when we map 10 to 100 cards, creating so many context in the back?

  • @malkythealky
    @malkythealky 10 หลายเดือนก่อน

    Very clear explanation, thank you

  • @isaacjon
    @isaacjon 10 หลายเดือนก่อน

    thanks i love it

  • @isaacjon
    @isaacjon 10 หลายเดือนก่อน

    nice 🔥

  • @darksider6113
    @darksider6113 10 หลายเดือนก่อน

    The idea is great but in nextjs 14 you can only use this component in the client side not on server side. Can anyone explain why?

    • @theobsidiangaming5381
      @theobsidiangaming5381 12 วันที่ผ่านมา

      React hooks can only be used in client side only. like useContext

  • @LocdNCoded
    @LocdNCoded 11 หลายเดือนก่อน

    Concurrently not parallel 😅

  • @ducky.coding
    @ducky.coding 11 หลายเดือนก่อน

    Let's see if I understood correctly the right use cases of this: I should/could use this whenever I have a component that needs some more details, but those details alone wouldn't be something that I could reuse elsewhere Seems like this, am I right? :)

  • @lucascampos4237
    @lucascampos4237 11 หลายเดือนก่อน

    This video has insane value. I'm working on my own web app, and this concept, when well applied and in the right situation, is a game-changer. The code without it, turns out to be simply a mess, but when applied properly, it provides the exact modularity needed. Awesome!

  • @luv.matters
    @luv.matters ปีที่แล้ว

    Everyone on TH-cam uses Typescript, but companies haven't converted yet 🤷🏼‍♀

    • @vincaslt
      @vincaslt ปีที่แล้ว

      Just remove types and you have JS in that case. You may be the first one to introduce TS in your company, I did that in 3 of the companies I worked at.

    • @luv.matters
      @luv.matters ปีที่แล้ว

      Maybe startups, but not main tech companies! Merry Christmas :)@@vincaslt

  • @danielson9490
    @danielson9490 ปีที่แล้ว

    Considering info & action prop as childrens would make this more clean and easy to understand

  • @ScottUmble
    @ScottUmble ปีที่แล้ว

    This is great, never thought of doing it this way.

  • @djoscarmix
    @djoscarmix ปีที่แล้ว

    I found this really intesting approach, but the disadvantage i see now its that all components become Client Components, instead server components and you can not fetch data directly in the component in the server side

    • @djoscarmix
      @djoscarmix ปีที่แล้ว

      btw if component is not too complex you can pass the data by props not using the context, keeping the server component

  • @anusharajendra389
    @anusharajendra389 ปีที่แล้ว

    Where is the link

  • @valenciawalker6498
    @valenciawalker6498 ปีที่แล้ว

    Thank you

  • @popuguytheparrot_
    @popuguytheparrot_ ปีที่แล้ว

    TH-cam bloggers grows to read documentation

  • @psyferinc.3573
    @psyferinc.3573 ปีที่แล้ว

    love this video. i learnt soemthing new and had to come back to it just to see what i missed.

  • @somebody-17546
    @somebody-17546 ปีที่แล้ว

    Wow. Very helpful.

  • @amaury_permer
    @amaury_permer ปีที่แล้ว

    I feel like we're getting back to writing plain Html 😅

  • @CarlosRodriguez-pn7fe
    @CarlosRodriguez-pn7fe ปีที่แล้ว

    That's an amazing explanation for me, thanks a lot!.

  • @PaulSebastianM
    @PaulSebastianM ปีที่แล้ว

    HOCs delegate rendering to other components while only composing them. They are not a solution to boolean flags. There is too much going on in this video and the premise is lost. Much of the boolean-ness can be more simply taken care of with optional props. Ie, no price, don't display the price. You don't necessarily need to pass a full DTO to a component. A component's interface should not leak implementation details.

  • @PaulSebastianM
    @PaulSebastianM ปีที่แล้ว

    Your to this looks awfully lot like having manually written the JSX to look like you want minus the ordering of the "slots". So, I'm not sure I see an improvement...

  • @miggu
    @miggu ปีที่แล้ว

    Thank you for the video. You can achieve namespacing by perhaps importing everything on a separate file as non default exports if the issue at hand is too many lines of imports. I will personally always favour <ProductImage/> to <Product.Image/> as on the latter you're creating a data dependency where the first one you can easily erase Product and <Product.image/> will still exist. You could then import everything in one line.

  • @qaz1617
    @qaz1617 ปีที่แล้ว

    Amazing, thanks

  • @JohnBuildWebsites
    @JohnBuildWebsites ปีที่แล้ว

    Great video. Not 100% sold on it all being a best practice, but really useful for everyone to understand how it works

  • @JlNGLEZ
    @JlNGLEZ ปีที่แล้ว

    I myself, prefer to develop components so they're easier to use consumer side, I feel like providing variations of a component as a prop is much easier, pass through an Id for the product, and have all logic relating to fetching and deciding layout to the component, learning curve for other developers is much nicer, and you're using the same composition in every place, it makes it much harder to fix bugs or make changes, where if it's inside the component, maintenance is much easier, you end up having to create wrapper components too many times with composition too so that things are reusable

  • @DanielSimaodaSilva
    @DanielSimaodaSilva ปีที่แล้ว

    Great video, but for me it's missing how to do unit test with those components

  • @HelenaDuGraus
    @HelenaDuGraus ปีที่แล้ว

    What intrigues me is that he imports several components that are used inside ProductCard outside of ProductCard and that logically speaking seems very wrong. It looks pretty nice on the innermost components, but look at the size of its imports list on the outermost layer. I think it's cleaner to have 6 components with 20 lines than 5 components with 5 lines and one with more than 100.

  • @Irakli008
    @Irakli008 ปีที่แล้ว

    10 seconds in and I’d already subscribed! Really liked this tutorial, looking forward to your future content. TH-cam needs a lot more React design pattern videos like this.

  • @detaaditya6237
    @detaaditya6237 ปีที่แล้ว

    It depends. If a function need the value from the previous function, then it's not a mistake

  • @RSo-fc3qf
    @RSo-fc3qf ปีที่แล้ว

    Hello bhaiya private company me job kaise paye please bataiyega bhaiya

  • @NicolasHussein-sq5ob
    @NicolasHussein-sq5ob ปีที่แล้ว

    Hey,, excellent video! Just a quick question. Let's imagine that you have to render 100 ProductCards. In that case, would you create 100 Context for each card? Thanks!