React Folder Structure Best Practices - For Large Projects

Sdílet
Vložit
  • čas přidán 27. 06. 2022
  • This is the folder structure pattern I follow whenever working on a big react application.
    Join our Discord: / discord
    🚀 Learn ReactJS By Building 6 Projects: codedamn.com/learn/reactjs-pr...
    🐙 GraphQL Course: codedamn.com/learn/graphql-fo...
    ► Buy Crypto on Coinbase: coinbase-consumer.sjv.io/PedroTech
    Social
    ▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬▬
    Website: machadopedro.com
    Linkedin: / machadop1407
    Instagram: / _pedro.machado_
    Github: github.com/machadop1407
    Business Email: pedro@pedrotech.co
    Tags:
    - ReactJS Tutorial
    - ReactJS and MySQL
    - NodeJS Tutorial
    - API Tutorial
    #reactjs #coding
  • Věda a technologie

Komentáře • 157

  • @frankthedsigner558
    @frankthedsigner558 Před 2 lety +1

    Wow, great video! I always find myself lost when having to setup a new project the correct way and I've watched many of your older folder structure videos in the past. Though, as my project scales it always gets messy but this is an awesome approach of doing it right from the start. Thanks for your updated video, love your content! keep it up!

  • @kovendanragupathi7632
    @kovendanragupathi7632 Před 2 lety +48

    @PedroTech, I really like your content on React since you are bringing production grade best practices. Please keep posting like these type of content Bro.

  • @khursheedalam3057
    @khursheedalam3057 Před 2 lety +1

    Loved it. I use the almost same folder structure. Few things I add in my project.
    For every component I have subcomponents.ts file in which I made styling for particular components.
    Create helpers.ts file for global helping functions.

  • @hizokadarkwolf
    @hizokadarkwolf Před rokem +1

    Thanks for the tips. The naming of files is always controversial, but organization is the most critical aspect. Insufficient naming and bad folder organization can be painful for the next developer working on a project... I learned that I had to rename and split the code into different files and folders in Angular. I will try this way, as I am just getting started on React.

  • @ricko13
    @ricko13 Před 2 lety +1

    You're killing it Pedro 🔥 keep it goin' 💯

  • @GabrielMartinez-ez9ue
    @GabrielMartinez-ez9ue Před 2 lety

    Y yo buscando este material! Finalmente! Thanks man

  • @OgamerRato
    @OgamerRato Před 2 lety +3

    I really want to thank you. I have been watching your vids and learning a loot. Not only that, but I just release my first project for a company a couple of weeks ago and didn't like the final result in a lot of aspects.
    Then a got into your channel and learned a loot, and it is making me a better programmer and helping me a loot at work.
    For that, really thanks man

  • @peladno
    @peladno Před 2 lety +1

    I'm learing programming so I was looking for a video like this. Thank you a lot :), especially because I have only one folder and are a lot of files and is a bit confusing heheheh

  • @ThColinPereira
    @ThColinPereira Před 2 lety +2

    This is such an amazing video

  • @malletdevoted
    @malletdevoted Před rokem

    Such a nice video, thanks for sharing.

  • @oziati533
    @oziati533 Před rokem

    Hi from Sweden 🇸🇪 😊 Love your videos and how you think in react, thanks for sharing!

  • @jokerbanny
    @jokerbanny Před 2 lety +1

    Thank you bro!

  • @BREXCool3
    @BREXCool3 Před 2 lety +1

    thankyou for sharing

  • @keenanjet7879
    @keenanjet7879 Před 2 lety

    I Heard in one of your previous videos that your always looking for content Idea, Id love to see a deep dive on The Graph since you GraphQL vids are awesome

  • @aymenbachiri-yh2hd
    @aymenbachiri-yh2hd Před měsícem

    Thank you so much

  • @nivethan_me
    @nivethan_me Před 2 lety +7

    at 10:15 naming components as index.ts will cause confusion when you working with multiple components in vscode. all components title will says index.ts. how to overcome this issue?
    i personally tried barrels on index.ts i write something like
    export { default } from './Navbar';
    then i create a new file called Navbar and write the component code there but this felt like a lot of work and lot of unnecessary files. any better idea?

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      Create a folder with the correct name, just import from the folder! You can also create file names that are specific and then create an index.ts file which imports and exports all the components. There is no right answer to this, it based on preference. I don't find it confusing, but I get why people might :)

  • @hardwired89
    @hardwired89 Před 2 lety +1

    Thank you, need more typescript content

  • @nurlanmehdiyev7428
    @nurlanmehdiyev7428 Před 2 lety +1

    Thank you

  • @RW-he5fu
    @RW-he5fu Před 6 měsíci

    nice video!

  • @Fizzify
    @Fizzify Před 2 lety +2

    Thanks.

  • @user-pq2uj8vj6m
    @user-pq2uj8vj6m Před 2 lety +1

    shit... I love you. you always give me what I want

  • @renatolins4670
    @renatolins4670 Před rokem +1

    Nice tutorial Pedro, I really liked it. I was just wondering if checking git/diff results involving component files, wouldn't be a bit harder in some situations or another as they are all named as 'index'. Anyway, thanks for sharing your knowledge man

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

      That could happen. I imagine you can give the component file a proper name and then in its "index" file just have its "default export".

  • @inelusjudelin4635
    @inelusjudelin4635 Před 2 lety +1

    🙌 Thanks

  • @avaplain9505
    @avaplain9505 Před 2 lety +2

    im also adding .stories and .styles to a component folder.
    .stories is for storybook and styles for css, scss, css modules or styles components

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      I put my styles either in the same component group or use reusable styles with something like styled-components!

  • @chrislye
    @chrislye Před 2 lety +3

    Thanks for sharing this @PedroTech! I just have one question - how would you deal with a common component that is required by more than one page? Where would you put it?

    • @zidanegimiga
      @zidanegimiga Před 2 lety +1

      Exactly!! But then again, folder structure is subjective to your project needs

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      Inside the commons folder!

  • @devkasunlakshitha
    @devkasunlakshitha Před 2 lety +1

    What you using to mange state instead of Redux?

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

    thanks bro

  • @cdey3886
    @cdey3886 Před 2 lety +3

    very useful content, thank you. Just and off topic question though, how'd you make the background animation?

  • @ademolaakindotuni5896
    @ademolaakindotuni5896 Před 2 lety

    This is awesome. I couldn't find the link to the GitHub repo in the description, do you mind sharing it here?

  • @marcus4619
    @marcus4619 Před 2 lety +1

    could you recommend some great extensions, for instance the way your files/folders have great icons. I cam from webstorm and looking for similar functionality

  • @cbijay
    @cbijay Před rokem

    Where would you like to put layout inside setup folder or common folder ?

  • @DuyTran-ss4lu
    @DuyTran-ss4lu Před 2 lety

    Awesome

  • @whonayem01
    @whonayem01 Před 2 lety

    Thanks

  • @rajarock454
    @rajarock454 Před rokem

    great ! which font you are using it's look pretty kindly let me know also with theme name.

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

    Would you not use a separate features folder?
    For example if you have a feature for creatingNotes, which you want to show on the dashboard page but also on the homepage.
    Wouldn't it be easier to have features/ creatingNotes. And then you can import creatingNotes to any page which needs it?

  • @nhutdev1324
    @nhutdev1324 Před rokem +2

    My rule of thumb is the longer and more descriptive the file name, the better. For files that export React components, I use PascalCase. For everything else, I use dash-case.

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

      don't use PascalCase, its a terrible practice

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

      ​@@starlord7526states random opion based info. Refuses to elaborate.

  • @baya8093
    @baya8093 Před 2 lety +3

    Hello Pedro, thanks for making this useful content. During the video you said you're not using Redux a lot, and I wonder which state management system you're using. Which one will be better?

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      I go over what I use here: czcams.com/video/t9WmZFnE6Hg/video.html

    • @butterfly7562
      @butterfly7562 Před 2 lety

      context, or lib such as zustand,jotai

  • @VietLe-qi2lh
    @VietLe-qi2lh Před 2 lety +3

    my current working project is using a folder structure like yours but it has many issue when it becomes huge. All team member agree to find other structure, which is easier to manage and work with it

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      What issues have ur team encountered? Ive used a similar structure in massive projects :)

  • @louaiboumedienne8276
    @louaiboumedienne8276 Před rokem

    @PedroTech, u said ur not using redux that much anymore, so what are u using as a state management solution?

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

    Pedro, onde está seu linkedin? está retornando erro na pagina pelo link na descrição

  • @codetheworld6721
    @codetheworld6721 Před rokem

    Thankyou..

  • @sujikumarts7470
    @sujikumarts7470 Před rokem

    Can we get the git hub location for a sample project with this directory structure , redux & graphql?

  • @diegounanue
    @diegounanue Před 2 lety

    You said that you don’t use redux that much today. What state manager do you use?

  • @rijogeorge5547
    @rijogeorge5547 Před 2 lety

    What if there is a component which shared by different pages in the app ?

  • @beninip
    @beninip Před rokem +5

    Hi PedroTech, I want to thank you for sharing this content to us. I'm wondering what's inside the common folder. You skipped it and you never went back on it.

    • @ryomaizen
      @ryomaizen Před rokem

      x2

    • @geovane2223
      @geovane2223 Před rokem

      common folder is basically where you store components that you use in two or more pages

    • @geovane2223
      @geovane2223 Před rokem

      but you can also just name it like components

  • @ponderatulify
    @ponderatulify Před 2 lety

    How do you do if you have posts and comments on the same page?

  • @marcus4619
    @marcus4619 Před 2 lety

    wont the test failure stack trace say index.test.ts and be confusing?

  • @ChinhNguyen-ye7nv
    @ChinhNguyen-ye7nv Před rokem

    great

  • @louislecouturier
    @louislecouturier Před 2 lety

    Thanks a lot Pedro ! What do you put in the common folder ?

    • @louislecouturier
      @louislecouturier Před 2 lety

      And what about css modules, do you name them "index" or the same name as the folder ?

  • @edetmmekut809
    @edetmmekut809 Před rokem

    yeah i prefer the absolute path in importing.And i notice u did not mention about reusable components like buttons,breadcrump,loader etc .For i do have a customised folder for reusable components

  • @user-pq2uj8vj6m
    @user-pq2uj8vj6m Před 2 lety +1

    thank you for your video. I'm always enjoying your video
    and I have a question what's "common" folders for? and also models.ts in component folder?

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety +1

      Common components / files that can exist in many different parts of the project!

    • @user-pq2uj8vj6m
      @user-pq2uj8vj6m Před 2 lety

      @@PedroTechnologies oh thank you, and can I ask you one more thing?
      you seem to have file name as "index.ts" at every component. but as I know component's name has to start Uppercase like Component.tsx.
      then is it not component file that index.ts? then what is in "index.ts"?

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

    love the structure! can you please share the github repo name?

  • @devproject8649
    @devproject8649 Před 2 lety +1

    I don't understand what you do when the path to the file is "../../". Do you use jsConfig to put the path? please answer me

  • @thesemicolon1971
    @thesemicolon1971 Před 2 lety +1

    I think you can't create complete using just .ts file because jsx will not work in ts.
    Correct me if i am wrong

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      In the video i mention that for components I use tsx and for just typescript files I use ts. But ts should work for writing components too!

  • @joaovictor-dl6ve
    @joaovictor-dl6ve Před 2 lety +1

    Pedro, vc não usa css modules ou style-components ou algo do tipo? Vc utiliza um arquivo .css normal msm?

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      I either use Styled-Components or TailwindCSS. If I use styled components, I will usually have a folder just for UI common elements. (Falei em inglês pra a glr entender tbm kkkkkk)

    • @joaovictor-dl6ve
      @joaovictor-dl6ve Před 2 lety

      @@PedroTechnologies kkkkkk boa!

  • @TricoliciSerghei
    @TricoliciSerghei Před rokem

    Thanks for the video.. Didn't find the link to the repository on github though, also checked on github, haven't seen it, maybe it has a different name?

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

    What do you use instead of Redux then?

  • @newbiedevtons
    @newbiedevtons Před 2 lety +1

    Hi, Pedro. Can I ask you something? If i want to build real word react js app then should I buy a reactjs courses? Thank you so much for your tutorial video

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety +1

      You don't need to buy a course in order to be good at building real world apps. I never bought a course in my life (although i sell one). It depends on the person, some people prefer to pay for courses because it holds them accountable.

    • @newbiedevtons
      @newbiedevtons Před 2 lety

      @@PedroTechnologies This reply inspired me more. Thanks a lot!

  • @aleksandarpopovic3615
    @aleksandarpopovic3615 Před 2 lety +2

    i like index.ts but the problem is when you are looking for a specific file, I create a file with the appropriate name and re-export with index.ts

  • @i-am-the-slime
    @i-am-the-slime Před 2 lety

    Isn't having one folder called "images" and one "svg" pretty ugly? Why not "png", "jpg", "svg" or "raster-images" and "vector-images". Or do you also have svg files in the images folder?

  • @SecretEyeSpot
    @SecretEyeSpot Před 2 lety +1

    Hey Pedro. What's the actual name of the repository for this video? I'm trying to understand what you're Common folder is and how you use it.

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety +1

      The commons folder is just filled with components that can be reused between multiple pages. Ex: search bar…

  • @augischadiegils.5109
    @augischadiegils.5109 Před 2 lety

    ❤️❤️

  • @licriss
    @licriss Před 2 lety +2

    I absolutely hate the term "best practices" since thinking the best has been discovered/established is a unneccessarily limiting mindset, but this is definitely a very good structure for UI projects larger than a couple of pages

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      I put it cause it has a bigger impact hahaha but like i said, there is no definitive best practice

  • @labiV1
    @labiV1 Před rokem

    I appreciate you making this video, as folder structure, granted, has caused me to pull my hair as our app is scaling. However, I do want to point out that there are some hooks that can be used globally and shouldn't be grouped under a specific page, is it ideal to create a "hooks" folder in the "src" parent folder?

    • @user-uw1rh4dg1y
      @user-uw1rh4dg1y Před rokem

      Questions can come in⬆️.

    • @joaovitor8485
      @joaovitor8485 Před rokem

      You can place your hook in the "commons" folder, like "commons > hooks", the same can be used to components, interfaces, functions, etc

  • @dat-ta
    @dat-ta Před 2 lety

    Hi, you guys have any idea for Next.js Folder Structure?

  • @alexdefaro
    @alexdefaro Před 2 lety +2

    Don't you think this is over engineering what should be a simple SPA structure?

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety +1

      This video is meant to be for large projects, and imo SPA is messy for large projects. It doesn’t scale well

    • @alexdefaro
      @alexdefaro Před 2 lety

      @@PedroTechnologies Thanks... Not sure If I would use React or any SPA framework for large (multipage) projects. You videos are great
      btw.

  • @easonhuang4031
    @easonhuang4031 Před 2 lety +1

    if all components file called index.tsx, if I open many files, there will be a lot of index.tsx on the right side, wouldn't this cause confusion?

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      I don’t find it confusing because i can see the folder name

  • @thecodingchallengeshow

    do big companies like facebook use this pattern and what am i supposed to do with react routing?

  • @truceheat1671
    @truceheat1671 Před 2 lety +1

    You said you didn't use redux anymore . I am curious do you use just context only ?

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      I talk about what I do here: czcams.com/video/t9WmZFnE6Hg/video.html

  • @filipevalentegomes2383
    @filipevalentegomes2383 Před 2 lety +2

    Regarding typescript, I would only use it in big projects or if you work with a big team. Reason being, if you are not super comfortable with typescript, you’ll waste way too much time figuring out, what and how to include types or interfaces. You basically have to code almost twice as much when you use typescript. You can get lost and lose focus on what you are actually trying to build. It has a lot of advantages, but only if you are really comfortable, otherwise you are just giving yourself more work

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety +3

      I understand your point, and I used to say the same. However I keep getting more inclined in using TS for all use cases. The reason being that the moment you get used to TS, it will not require that much extra work. Tbh the point of ts is to prevent bugs, a JS project will never be as safe as a TS project.

    • @filipevalentegomes2383
      @filipevalentegomes2383 Před 2 lety +2

      @@PedroTechnologies 100% that’s why I said unless you are comfortable with it. I think it’s best to use it in personal projects at first to get used to it. Once you are comfortable with it, it actually makes it easier for testing later on.

  • @MukeshKumar-um2wg
    @MukeshKumar-um2wg Před 2 lety +1

    How do we manage shared components in this file structure?

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      You can put it inside of the commons, or possibly have a "features" folder where you can add specific feature logic that is shared!

  • @Joseph-do9ue
    @Joseph-do9ue Před 2 lety +1

    Please make a tutorial for typescript for beginers

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      I have a couple of them: czcams.com/play/PLpPqplz6dKxW1LdiHpJMyC5bzuzGxKlFm.html

  • @indrajithpatel5966
    @indrajithpatel5966 Před rokem

    i dont see an index.ts at your pages level. How do you combine these components inside your pages

  • @Pareshbpatel
    @Pareshbpatel Před 2 lety +1

    A very useful tutorial on Folder Structure for React Apps. Thanks, Pedro
    {2022-06-08},{2022-06-29}

  • @PedroNovo93
    @PedroNovo93 Před rokem +1

    @PedroTech you missed the common folder, haven’t you?

    • @oziati533
      @oziati533 Před rokem

      Yepp, maybe something as a part 2 CZcams post 😅

  • @MasharipovSaidbek
    @MasharipovSaidbek Před 2 lety

    GL

  • @AyomiposiAborisade-yu5is
    @AyomiposiAborisade-yu5is Před 8 měsíci

    How to get the images properly, without importing it individually
    And how to get absolute path of any file

  • @chizuru1999
    @chizuru1999 Před 2 lety

    I would like a video on state management of react. What to use for enterprise grade applications? Thanks.
    I am familiar with Angular and just can't get head over the mess of a framework react is.

    • @chizuru1999
      @chizuru1999 Před 2 lety

      Also the way it is going ahead it feels like react will just become angular with all these features... 😂😂 Later all you know they might even add a react cli.

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

    Personally I find it confusing to have multiple index.tsx files open and being unable to tell at a glance which components they are associated with. I do see how it gives the code a nice clean feel, though.

  • @jorgeriveramx
    @jorgeriveramx Před rokem +1

    What you came for starts at 4:10

  • @alok9337
    @alok9337 Před 2 lety +1

    how can i good in frontend development . because when I creating project on my own my mind don't think how to do that . what should I do to improve my self.

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety +1

      Time and practice is the answer. You don't need to worry about this if you are a beginner. Also, working a job in the industry can help a lot!

    • @alok9337
      @alok9337 Před 2 lety

      @@PedroTechnologies thanks bro

    • @alok9337
      @alok9337 Před 2 lety

      Your content is lot help me understand things.

  • @haina3052
    @haina3052 Před rokem +1

    So, for each page you have a folder. Where do you put your layout component like ? What about a button component that is gonna be used in different pages? You duplicate them everywhere?

    • @PedroTechnologies
      @PedroTechnologies  Před rokem +1

      You put those in the commons folder. So the commons folder structure would look like: /commons/components/footer/index.ts

  • @mumk
    @mumk Před 2 lety

    where is your index.tsx for each page

    • @dobrilbojilov8184
      @dobrilbojilov8184 Před rokem +1

      Yep i want to know this also. Where is starting point for every page? I didn't saw index.tsx in root post page folder for example.

  • @alii2284
    @alii2284 Před 29 dny

    dude you didn't talk about the "common" folder

  • @SirXtC
    @SirXtC Před 2 lety +1

    awesome video. maybe im just neckpicking...but saying "I'm back here with another video" its just very redundant in a way... since this is youtube lol.

  • @edetmmekut809
    @edetmmekut809 Před rokem

    I can't joint your discord channel via the above link ,can u please resend me the lastest link

  • @user-wl2xp8yo6x
    @user-wl2xp8yo6x Před 2 lety +1

    1. Ты забыл про service, где должна хранится бизнес логика приложения, а не библиотеки/фреймворка.
    2. Папка componenst я считаю лишней, если pages уже подразумевает что это компоненты зачем там создавать еще одну папку с компонентами?

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      Pages are the routes, components are specific components that are used in the pages. Usually pages turn out to be very big, so separating parts of it into components make ur code more organized. Also, components should be separated in a way such that they are not very smart, each component should have their own purpose.

    • @user-wl2xp8yo6x
      @user-wl2xp8yo6x Před 2 lety

      ​@@PedroTechnologies
      /components/
      [page](comments)/List/index.jsx
      [page](comments)/List/List.container.jsx
      [page](comments)/Comment.service.js
      [page](comments)/Comment.repository.js
      header/index.jsx (global component)
      footer/index.jsx (global componen)

  • @dailymeow3283
    @dailymeow3283 Před 2 lety

    Just use next js, it is structured

  • @lmisrealkmilk6623
    @lmisrealkmilk6623 Před 2 lety

    Where is your UBC cs video?

    • @PedroTechnologies
      @PedroTechnologies  Před 2 lety

      I privated it bc im not a CS student anymore lmaoo i switched to math!

    • @lmisrealkmilk6623
      @lmisrealkmilk6623 Před 2 lety

      @@PedroTechnologies can you make a vid on why you switched?

  • @rychei5393
    @rychei5393 Před rokem

    Skip the fluff to 3:20

  • @KRaven950
    @KRaven950 Před rokem +1

    That is definitely not a folder structure for large projects. Maybe for medium ones

    • @PedroTechnologies
      @PedroTechnologies  Před rokem +1

      This is the folder structure for one of the biggest tech companies in the world.

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

      @@PedroTechnologies Could you name a few?

  • @makl-the-oracle
    @makl-the-oracle Před rokem

    Not it

  • @johnddonnet5151
    @johnddonnet5151 Před 2 lety +1

    You didn't even open commons folder