Creating High-Quality React Components: Best Practices for Reusability

Поділитися
Вставка
  • Опубліковано 26 січ 2025

КОМЕНТАРІ • 131

  • @Luxcium
    @Luxcium Рік тому +61

    What I love the most about Josh is that he is smart and he assumes that we are smart… At the same time he is learning and he assumes that we are learning too… from that we have his iconic balanced approach where he is never assuming that we know everything and he is never going to treat us like if we know nothing at all… he is outlining the elements that we need to be aware of if we are new to the topic and then he is introducing the core of the topic… I love that approach it’s perfect for me I love that style of teaching we have the felling that we are on the same level and growing up together… This is why I always repeat myself and say that Josh is such a good communicator 😊😊😊😊

    • @Hellbending
      @Hellbending Рік тому +3

      You e managed to summarise exactly what I couldn’t quite put my finger on haha. His ability to show he’s still human (make mistakes/learn etc) whilst being aware of the core fundementals on a topic.
      Thanks for the comment, helped further my own understanding and give some words to this style of teaching for me.

    • @undefined5132
      @undefined5132 Рік тому

      Minimum requirement for programmer: should be able to dig deep.

  • @semx8372
    @semx8372 Рік тому +36

    Good! Instead of ButtonHTMLAtrrs you can also use ComponentProps (as well as 'div', 'input' etc) to make code look cleaner :)

  • @toheebajayi1454
    @toheebajayi1454 5 місяців тому +1

    The name should be changed from "Josh tried coding" to "Josh is coding". Love what you're doing man, thanks.

  • @bogrisss
    @bogrisss Рік тому +1

    Brilliant content! I am watching you for a few weeks now. One on the few channels in dev that actually worth watching! ❤

  • @codewithguillaume
    @codewithguillaume Рік тому +1

    That was something that really fired me up months ago ❤🎉

    • @joshtriedcoding
      @joshtriedcoding  Рік тому

      Really handy to reuse components once you figure out how and take the time to make them reusable

    • @AlexSilva-ye2lp
      @AlexSilva-ye2lp Рік тому

      I did not understood why to use this approach when we can use the globals.css to create default styles and variant styles too.

  • @zachomis
    @zachomis Рік тому +2

    Bro, thank you. Very simple yet detailed at the same time. You covered so many important concepts.
    This might not work well for a beginner, but as someone who's been on the TS journey, it's perfect.

  • @zacharyphilipp4871
    @zacharyphilipp4871 Рік тому +7

    what is the typescript snippet you used to make that btn component so quick?

  • @affanthebest
    @affanthebest Рік тому +2

    What is the name of extension using which you initiated React function component "fc"

  • @farhaankhan3294
    @farhaankhan3294 Рік тому +6

    What's the name of that vscode extension which you're using by typing fc for typescript react functional component?

    • @CanRau
      @CanRau Рік тому

      What do you mean?

    • @duynd243
      @duynd243 Рік тому

      React Snippet extension will help you do that

  • @abhiramsatpute
    @abhiramsatpute Рік тому +11

    Are there any performance improvements that back up this approach? Or is it just for Developer Experience? Since it may reduce Code Redundancy, we are also installing extra libraries in exchange of it

    • @botelhoh4535
      @botelhoh4535 Рік тому +4

      I like to use only the lib called classnames. I don't see the necessity of class-variancy-authority.

    • @AlexSilva-ye2lp
      @AlexSilva-ye2lp Рік тому

      @@botelhoh4535 me too, I think its much easier to just create the default styles at the globals.css file and then create the variant classes their.

    • @PanosPitsi
      @PanosPitsi Рік тому

      @@AlexSilva-ye2lpthis is a terrible approach you can’t unit test css classes. Only make utility classes in css, for example background-card or header-prominent. If you want to make an actual card turn it into a component.

  • @ahmad.shiddiq
    @ahmad.shiddiq Рік тому

    What a goat!
    tysm, i really need this for future planning when i work on react again

  • @janupasilva
    @janupasilva Рік тому +12

    Really impressed with the content man, really like this kind of content ♥

  • @indiancuriousvoice8773
    @indiancuriousvoice8773 Рік тому +5

    Why to use that tailwind classes inside cva when you can directly use inside button Or simply you can create some global css classes and use that classname

  • @muchis
    @muchis Рік тому +5

    Awesome!
    Just one question:
    when you create forwardRef you add both but doesn't ButtonProps already contain everything from HTMLButtomElement from the interface you created above it? Why is it necessary to pass HTMLButtonElements again there?

    • @resh7064
      @resh7064 Рік тому

      The HTMLButtonElement here is the return type of the component.

    • @deanolium
      @deanolium 4 місяці тому

      The forwardRef generic type parameter list (ie, the bit between the angle brackets ) takes in two values to replace two generics. The first is the type of the thing you're providing the ref to. The second is the props that the component takes.
      So in this case, HTMLButtonElement refers to the tag which the ref is referencing. If it was a div element instead, then it would be HTMLDivElement. Then the ButtonProps bit is just saying which props the element could take. There's some repetition, but it because you could not bother with sending props to the tag in case you want to restrict what the consumer of your component can do. Lots of flexibility even though in most cases it'll be bad practice to not just pass the props down.

  • @jamesdenmark1396
    @jamesdenmark1396 Рік тому

    Perfect video, perfect speed, i love it! I usally speed up all videos x2 just to get to the point, I like the libs he is using, I didn't know about them before, and I usually have variants and size in many components, im going to use these lib in my project. LIKE AND SUBSCRIBED!

  • @ahmedabdellatif2152
    @ahmedabdellatif2152 8 місяців тому

    i dont know why , but i was keep counting how many "Really really" was there xD xD thanks for this fruitful videos!

  • @quinnsalas6403
    @quinnsalas6403 Рік тому

    Insanely valuable - thank you for taking the time!

  • @dimasadnan4873
    @dimasadnan4873 Рік тому +4

    Great tutorial! Just one question. Do the tailwind classes we write in those cva things affected by prettier with tailwind's extension?

    • @joshtriedcoding
      @joshtriedcoding  Рік тому +1

      Not sure, good question. Haven’t tried that out yet

  • @paramsstudio2902
    @paramsstudio2902 Рік тому

    Clean and Straight Forward and Thanks for also mentioning the keyboard shortcut i always have defficulty to find the vs code keyboard shortcut because I thinks its a time waste to learn keyboard shortcut i learn in process not explecitely

  • @kdev_007
    @kdev_007 7 місяців тому

    can you please share the extension you made the basic component only typing 'fc'?

  • @billyfigueroa1617
    @billyfigueroa1617 11 місяців тому

    Interesting tooling. Is there a reason you did not use ComponentProps instead of the interface route?
    I have found through research that we should default to using types as opposed to interfaces. Also I believe using FC is also no longer best practice but I could be tripping
    Great video though. Don't think I am criticizing just because I asked some questions

  • @jo.repossi
    @jo.repossi 6 місяців тому

    Bravo! Can you make the same
    Idea but with an input and react hook form?

  • @바리오
    @바리오 Рік тому +3

    did you define typescript react code snippet like "fc" by yourself? or are you using extension?

    • @techworld3255
      @techworld3255 8 місяців тому

      The extension is called ES7+ React/Redux/React-Native snippets

  • @mp6086
    @mp6086 11 місяців тому

    Great video! What about dark mode? Is there a way to create dark mode modifiers for each variant and add darkMode prop to the component, or is it necessary to create independent dark mode variants?

  • @dontignore5567
    @dontignore5567 8 місяців тому

    Question about component FILE NAMES. Which compoennt file name should be PascalCase and which should be just regular lowercase ?

  • @RutvikrajChampavat
    @RutvikrajChampavat Рік тому

    Does anyone know which react snippet extension Josh is using. He created a typescript react component only using "rc" snippet. I am already using ES7+ React/Redux/React-Native snippets but I don't it provides this snippet.

  • @luongtuananh3661
    @luongtuananh3661 Рік тому

    could you explain how to build the styled function of MUI? I see it has some features like inheritance style's-component and namespace classes

  • @codebymoonlight
    @codebymoonlight Рік тому

    This is great content Bro. I enjoyed every bit of it

  • @TouseefKhan-iy9px
    @TouseefKhan-iy9px Рік тому +1

    Amazing! Please create more similar typescript videos.

  • @CoryTheSimmons
    @CoryTheSimmons Рік тому

    Amazing pattern. Thank you for sharing it with us!

  • @MisouSup
    @MisouSup Рік тому

    Why is there no intellisense when you're typing tailwind class names? Is there any easy way to fix this?

  • @oddfeeling7956
    @oddfeeling7956 11 місяців тому

    All thats left now is auto complete for the ButtonVariant object and this would be perfect.

  • @michaelmannucci8585
    @michaelmannucci8585 Рік тому

    What I don’t understand is… this button wouldn’t only be a … but what if you wanted to have the button component as a or

    • @kc-bytes743
      @kc-bytes743 Рік тому

      no , he giving us option to create reusable button

  • @DioArsya
    @DioArsya Рік тому +1

    nice! Anyway, CVA re-exported `clsx` package they called it cx, so it's unnecessary to install `classnames`

    • @shadensnow
      @shadensnow Рік тому

      CVA does not surface the types such as 'ClassValue[]' though

  • @SMILESHOW1337
    @SMILESHOW1337 Рік тому

    how can i pass not only input but also label to Reac.ComponentProps??

  • @nickwoodward819
    @nickwoodward819 Рік тому +1

    Hey Josh, great video, thanks! Just wondering how we can make a disabled variant?

    • @felipek.deboni8157
      @felipek.deboni8157 Рік тому

      Disabled is not a variant, it's an attribute. Just style it using the attribute pretty much like .myClass[disabled] in CSS.
      You can either define it for all of them, individually or both. Tailwind uses "disabled:" prefix for it :)

  • @iftyislam6761
    @iftyislam6761 Рік тому

    for example if I have a component that has a wrapper and button then how can I utilize cva to use conditional classes in both?

  • @shujin9027
    @shujin9027 Рік тому

    Just curious, do u use VSC in real work projects with all these manual lib imports, or u doing it for us?

  • @valentinbenitobousquet6166
    @valentinbenitobousquet6166 Рік тому

    Incredible work and clarity. Keep going! 🫡

  • @ThanHtutZaw3
    @ThanHtutZaw3 Рік тому

    How do you add children without passing props in button ?

  • @kc-bytes743
    @kc-bytes743 Рік тому +1

    Material UI doing for us this thing in advance , why we struggle too much ,MUI give us option of Theme in which we can do custom theme , Create reusable design

  • @sebastian-nunez
    @sebastian-nunez Рік тому

    Nice! Now the shadcn ui components make sense!

  • @AdsonCicilioti
    @AdsonCicilioti Рік тому

    Nice man... Make an video about ui components library and how build and re-use on an application. Thanks!

    • @joshtriedcoding
      @joshtriedcoding  Рік тому

      Cheers dude. I think a key part of a UI lib is to be very reusable by default. Personally I think shadcn has done a great job at this with his library

  • @occo5877
    @occo5877 Рік тому

    Would be great to make a video about your navigation in vscode, looks interesting

  • @tanvirhossain9781
    @tanvirhossain9781 Рік тому

    Hey Josh, Its amezing to have your videos, i just want to know how do you create tsx file with just fc snipes? Please let me know

  • @rifkysatyana2415
    @rifkysatyana2415 Рік тому

    Awesome stuff, I really wanna make a project with React + TypeScript. Have only made with Javascript.

  • @sergey_gabrielyan1001
    @sergey_gabrielyan1001 Рік тому

    Hello👋. In my project I have primary and secondary buttons with global .btn class which I use on a and button tags, but I want to use Button component, because lots of project examples use that option. If not difficult, can you give examples why to use Button component, what are the benefits?

  • @JohnDoe-gf1kh
    @JohnDoe-gf1kh Рік тому

    Great Content Josh! as always. I have a question about the video. Please could you tell me the reason that you put 'clsx' in the cn function. I think it doesn't matter if we don't have that. 🙄

    • @joshtriedcoding
      @joshtriedcoding  Рік тому +1

      True, I think it's not needed anymore. As far as I know, tailwind-merge uses clsx under the hood anyways

  • @ejikemekingson6336
    @ejikemekingson6336 Рік тому

    Thanks so much Josh

  • @joewulf7378
    @joewulf7378 Рік тому

    Display -> Spaces: 4
    Editor -> Spaces: 2

  • @DanteMishima
    @DanteMishima Рік тому

    How is styling not the point sir? How?

  • @ksidharth1994
    @ksidharth1994 Рік тому

    Why not write plain old CSS?

  • @motivation2code
    @motivation2code Рік тому

    please, create video about NextJS roadmap. Thank you.

  • @WirelessGus
    @WirelessGus 5 місяців тому

    You offer Contractor work 💼?

  • @cod-the-creator
    @cod-the-creator Рік тому +2

    The concept of defining styles inside of your Button component then using those in other random non-Button components is pretty absurd to me.

  • @michaelpacheco7421
    @michaelpacheco7421 Рік тому

    You could have used namespaced components too

  • @bestvocabulary8362
    @bestvocabulary8362 Рік тому

    Didn't understand use of forward ref

  • @greendsnow
    @greendsnow Рік тому +1

    Svelte Skeleton UI has already solved this issue...

  • @georgenonis5967
    @georgenonis5967 Рік тому

    instead of forwarding ref why don't you give it just another name and pass it normally? instead of ref - btnRef

  • @ananas32069
    @ananas32069 Рік тому

    Amazing content

  • @donalnoye4946
    @donalnoye4946 Рік тому +1

    emmm, it's a button from shadcn/ui

    • @bestvocabulary8362
      @bestvocabulary8362 Рік тому

      Exactly 😂 I just searched from shadcn component that what is cva and got this vdo

  • @myrachanto
    @myrachanto Рік тому

    this amazing thank you

  • @belkocik
    @belkocik Рік тому +1

    I would love to see a series where you a have project to build and showing how to write an app that would be easy to scale and have a lot of reusable components :D

    • @joshtriedcoding
      @joshtriedcoding  Рік тому

      Any certain project you’d like to see?

    • @belkocik
      @belkocik Рік тому

      @@joshtriedcodingany type of e-commerce website 😌

    • @homiecoder
      @homiecoder Рік тому

      @@joshtriedcoding Thx for another banger! I agree with @bubuq3, my 2 cents maybe a chat app or ecommerce app?

    • @syamsarosa5916
      @syamsarosa5916 Рік тому +1

      @@joshtriedcoding maybe create a CMS like Wordpress, but using NextJS? with plugin, theme, WP hooks system, etc.

    • @kc-bytes743
      @kc-bytes743 Рік тому

      @@joshtriedcoding E commence project that merge multiple store into one UI

  • @xdriftxmyusik
    @xdriftxmyusik Рік тому

    great video man \m/

  • @danielgend7856
    @danielgend7856 Рік тому

    josh bester mann 🎉

  • @OscarD3v
    @OscarD3v Рік тому

    Muy bueno, gracias

  • @SanderCokart
    @SanderCokart Рік тому

    Clsx is kinda useless now tailwind merge and tailwind join exists. Import {twMerge, twJoin} from 'tailwind-merge';

  • @Spkntei
    @Spkntei Рік тому

    Nice !

  • @simonkling5623
    @simonkling5623 6 місяців тому

    ctrl + spacebar !!

  • @thip1754
    @thip1754 Рік тому

    shadcn is built upon this haha

  • @fernandovillalba3346
    @fernandovillalba3346 Рік тому

    nice!

  • @i-am-the-slime
    @i-am-the-slime 8 місяців тому

    Wieso nicht deutsch?

  • @lasindunuwanga5292
    @lasindunuwanga5292 9 місяців тому

    too much abstraction will eventually kill you

  • @tangle5069
    @tangle5069 Рік тому +3

    common man why are you afraid of the truth , copying open source code doesn't mean you have done it yourself, marking my comments as spam won't work

    • @joshtriedcoding
      @joshtriedcoding  Рік тому +7

      Im not marking any comments as anything. It's not a secret that I learn from open-source code too. I share what I learn on this channel, and always credit the creator if I do so. If you had read the readme, you'd know that, even though shadcn specifically states no attribution is required whatsoever

    • @tangle5069
      @tangle5069 Рік тому

      @@joshtriedcoding sorry josh for my hard talk, but it would have been nice , if you have mentioned about it , it not about atrribution , but mentioning shadn to that people, so that they could benefit more from his complete work. Thanks.

    • @joshtriedcoding
      @joshtriedcoding  Рік тому +4

      @@tangle5069 I made a whole video about his work because I was so impressed with it: ua-cam.com/video/DeLHGl936Fo/v-deo.html

    • @tangle5069
      @tangle5069 Рік тому

      @@joshtriedcoding Aplogies from my side, i hadn't watched that video, anyways keep doing the good stuff.

  • @deepaksingh-qd7xm
    @deepaksingh-qd7xm 7 місяців тому

    nextjs is bloddy shit its too much complicated for a simple button

  • @yaxahir4674
    @yaxahir4674 11 місяців тому

    wha

  • @umitdemirci7394
    @umitdemirci7394 Рік тому

    shadcn

  • @enversecilmis7627
    @enversecilmis7627 Рік тому

    Just write an object literal and use it as a map smh.

  • @ashron4472
    @ashron4472 Рік тому +3

    This is really not that useful. No offense, but thx for the info

    • @joshtriedcoding
      @joshtriedcoding  Рік тому +1

      No offence taken, what would make this more useful in your opinion?

    • @homiecoder
      @homiecoder Рік тому

      @@joshtriedcoding Boss response!

    • @eminvesting
      @eminvesting Рік тому +9

      @@joshtriedcoding you jump too much and too fast, it's a good pace for intermediate developers but not good for beginners. What you explain is aimed at beginners, an intermediate dev knows this stuff. So since you're viewers are most likely going to be beginners, you need to adapt your pace to them. Can't just jump around setting types they never even heard of, importing packages without thoroughly explaining them, using typescript code in a "create Reusable React components" titled video etc.
      Your average viewer doesn't even know what a ref is, you just threw it in their face. This kind of videos are better suited for a series rather than a one time explainer. In a series you go step by step and get them to your pace (+ more content, more watchtime etc which benefits you as well. You can make people binge a series, that does wonders for the algo)
      Just be smarter :) if you really spend a couple minutes thinking about it or if you just rewatched the video before uploading it you would probably have came to the same conclusions. Good luck buddy, looking forward to see your future content as you get used to YT

    • @joshtriedcoding
      @joshtriedcoding  Рік тому +8

      @@eminvesting Thanks very much for the detailed critique! That was possibly the most valuable feedback I've gotten.

    • @PedroFernandez-iv2uv
      @PedroFernandez-iv2uv Рік тому

      @@eminvesting agree with your comment.

  • @JEsterCW
    @JEsterCW Рік тому

    xD

  • @DesiMuscles
    @DesiMuscles Рік тому

    bro plz go slow

  • @VictorMartins239
    @VictorMartins239 Рік тому

    inline css 🤮

  • @thelayoutguy
    @thelayoutguy Рік тому +1

  • @VladimirMiroshnichenko64
    @VladimirMiroshnichenko64 Рік тому +1

    you can't reuse this "reusable" component on the projects which are not using tailwind

    • @albatros-av
      @albatros-av Рік тому

      why wouldn't you just use tailwind in everything? i mean if it's part of your stack, you'd use it wherever you can

  • @Misica11000
    @Misica11000 Рік тому

    You need to talk slowly,and some more explanation about every thing you code would be nice...

  • @MJ-vx5cz
    @MJ-vx5cz Рік тому

    Man i just love u🫶🏼