Vincas Stonys
Vincas Stonys
  • 6
  • 103 978
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
zhlédnutí: 81 573

Video

Encrypted Notes App Tutorial for Beginners | React.JS + TypeScript
zhlédnutí 8KPřed rokem
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
zhlédnutí 2,8KPřed rokem
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...

Komentáře

  • @patrickudekwe
    @patrickudekwe Před 2 dny

    Is this for only software developers?

  • @PhilipIsaacs
    @PhilipIsaacs Před 9 dny

    Excellent Tutorial.

  • @Lemmy4555
    @Lemmy4555 Před měsícem

    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. Před měsícem

    thank you for sharing!

  • @user-gm3lg8gp3m
    @user-gm3lg8gp3m Před měsícem

    Great tip!

  • @shane3744
    @shane3744 Před měsícem

    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?

  • @henriquematias1986
    @henriquematias1986 Před 2 měsíci

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

  • @einfacherkerl3279
    @einfacherkerl3279 Před 2 měsíci

    first time someone wrote react code using a typewriter!

  • @rea_kr
    @rea_kr Před 2 měsíci

    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 Před 2 měsíci

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

  • @angstrom1058
    @angstrom1058 Před 3 měsíci

    Great video, Vincas. Thank you.

  • @XDBjoernXD
    @XDBjoernXD Před 3 měsíci

    wow, I learned a lot

  • @miettoisdev
    @miettoisdev Před 3 měsíci

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

  • @toonmystoryanimated.6766
    @toonmystoryanimated.6766 Před 4 měsíci

    No link

  • @streetjnoun
    @streetjnoun Před 4 měsíci

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

  • @frank13621
    @frank13621 Před 5 měsíci

    Clicking through these posts and half no longer exist and many are just send resume to an email with hardly any description or salary. Are you getting replies applying on this?

  • @justAbeautifulSoul409
    @justAbeautifulSoul409 Před 6 měsíci

    for independent calls allsetteled is better than all

  • @Gangbuster74
    @Gangbuster74 Před 6 měsíci

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

  • @malkythealky
    @malkythealky Před 6 měsíci

    Very clear explanation, thank you

  • @isaacjon
    @isaacjon Před 7 měsíci

    thanks i love it

  • @isaacjon
    @isaacjon Před 7 měsíci

    nice 🔥

  • @darksider6113
    @darksider6113 Před 7 měsíci

    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?

  • @LocdNCoded
    @LocdNCoded Před 7 měsíci

    Concurrently not parallel 😅

  • @ducky.coding
    @ducky.coding Před 7 měsíci

    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 Před 8 měsíci

    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 Před 8 měsíci

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

    • @vincaslt
      @vincaslt Před 8 měsíci

      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 Před 8 měsíci

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

  • @danielson9490
    @danielson9490 Před 9 měsíci

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

  • @ScottUmble
    @ScottUmble Před 9 měsíci

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

  • @djoscarmix
    @djoscarmix Před 9 měsíci

    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 Před 9 měsíci

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

  • @anusharajendra389
    @anusharajendra389 Před 10 měsíci

    Where is the link

  • @valenciawalker6498
    @valenciawalker6498 Před 10 měsíci

    Thank you

  • @popuguytheparrot_
    @popuguytheparrot_ Před 10 měsíci

    CZcams bloggers grows to read documentation

  • @psyferinc.3573
    @psyferinc.3573 Před 10 měsíci

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

  • @somebody-17546
    @somebody-17546 Před 10 měsíci

    Wow. Very helpful.

  • @amaury_permer
    @amaury_permer Před 10 měsíci

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

  • @CarlosRodriguez-pn7fe
    @CarlosRodriguez-pn7fe Před 10 měsíci

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

  • @PaulSebastianM
    @PaulSebastianM Před 10 měsíci

    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 Před 10 měsíci

    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 Před 11 měsíci

    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 Před 11 měsíci

    Amazing, thanks

  • @JohnBuildWebsites
    @JohnBuildWebsites Před 11 měsíci

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

  • @JlNGLEZ
    @JlNGLEZ Před 11 měsíci

    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 Před rokem

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

  • @HelenaDuGraus
    @HelenaDuGraus Před rokem

    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 Před rokem

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

  • @detaaditya6237
    @detaaditya6237 Před rokem

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

  • @RSo-fc3qf
    @RSo-fc3qf Před rokem

    Hello bhaiya private company me job kaise paye please bataiyega bhaiya

  • @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!

  • @mrdeurknopp
    @mrdeurknopp Před rokem

    I can only like this video once unfortunately... Really brilliant explanation and example, well done :)

  • @iamalchemist579
    @iamalchemist579 Před rokem

    Can you post the GitHub of this?