Keep your React components in the same file

Sdílet
Vložit
  • čas přidán 8. 07. 2024
  • #shorts
  • Zábava

Komentáře • 17

  • @sujanbasnet7868
    @sujanbasnet7868 Před 17 dny +6

    I personally dont enjoy reading through large files. I get lost quick.

  • @elie2222
    @elie2222 Před 12 dny +2

    I also do this. But the example is pretty small. When you start getting to 500 line files with a lot of useState and useEffect type logic I find it helpful to break it down into a folder. Not the components folder, just the folder where this code was before.

  • @willb.r2055
    @willb.r2055 Před 14 dny +1

    I usually write components up to 150 lines of code until I make sure everything is working fine and then start breaking them into smaller components only if I need to use some part somewher else or if they need to get larger than that

  • @omkarsheral8559
    @omkarsheral8559 Před 18 dny +3

    this can be solved using proper folder structure

  • @obouchari
    @obouchari Před 13 dny

    I've been doing it that way and I concluded with this rule, if the component is going to be used in multiple places it makes sense to put it in its own separate file, if it's only used in one parent component or it accompanies an exported parent component at all times I keep them is the same file. Except when you're using Next and a component needs to be flagged as a "client component", then you're forced to extract its logic to its own file.

  • @emreq9124
    @emreq9124 Před 15 dny +1

    I do search components using vscode shortcuts. For example I do just Cmd + P then write component name. And bum here it is. But in your way, we have to use global search. Also css may messy. I may try in small projects but, in real world projects hell no

  • @geelemo
    @geelemo Před 18 dny +7

    If it's just you fine. If you're working with others, you need to clean it up fr

  • @gumilhopipoca4041
    @gumilhopipoca4041 Před 19 dny +3

    I would do that, but these components are usually client components, so i would have to create a new file anyway

    • @leerob
      @leerob  Před 18 dny +2

      I actually don't mind splitting for client components, because it's basically going into "another world". Your client component gets prerendered, but then _also_ adds a script tag to run React in the browser.

    • @MichaelPresecan
      @MichaelPresecan Před 15 dny

      ​@@leerobthe "other world" is technically true, but not necessarily a natural composition mental model, which presumably React and Next are driven by. I don't mind putting a client component in a new file, but every time I do, I wish there was no such hassle.

  • @Sindoku
    @Sindoku Před 18 dny +2

    I hate vertical scroll though so probably not for me

  • @yachujoshi
    @yachujoshi Před 15 dny +1

    What's this VSCode Theme? Looks clean & minimal.

  • @yashsolanki069
    @yashsolanki069 Před 18 dny

    Is the source code already public for this ??
    This approach is quite common in enterprise application and complex codebases but i would say proprr folder structure is better than having everything in one file like this.

    • @leerob
      @leerob  Před 16 dny

      github.com/vercel/nextjs-postgres-nextauth-tailwindcss-template

  • @togya4
    @togya4 Před 17 dny +4

    Naaah bro you are drunk for sure

  • @utkuonursahin1237
    @utkuonursahin1237 Před 17 dny

    Do I have to export all compound components explicitly? I mean should I default export Breadcrumb then export function BreadcrumbList(){}, export function BreadcrumbItem(){} and so on. With this way I can use Client Compound components inside Server components but I have question. Why I can't use them like export default Breadcrumb, and then no exports just Breadcrumb.BreadcrumbList = function (){}, Breadcrumb.BreadcrumbItem = function () {} if I do it in this way it gives React Client Manifest error but why?

  • @r-i-ch
    @r-i-ch Před 13 dny

    Lemme join the chorus of "oof, really can't see this as a good idea" - esp. with Tailwind, you've got a ton of code to parse if you want to refactor anything or especially work with someone(s) else on the same project. I think this implies you do a lot of solo work perhaps?