Folder structure in React - Complete Guide

Поділитися
Вставка
  • Опубліковано 12 вер 2024
  • 🚀 Project React → cosden.solutio...
    📥 Import React (Newsletter) → cosden.solutio...
    Join The Discord! → discord.cosden...
    In this video we will learn about folder structure in React. I will show you what I've come to learn as one of the best ways to structure your folders in your React application. Whether you're using Next.js or Remix or Gatsby, or even a simple create react (or vite) app, this folder structure will be a great foundation to get you started.

КОМЕНТАРІ • 94

  • @cosdensolutions
    @cosdensolutions  5 місяців тому +2

    Hope you enjoyed the video! I also have a really cool and unique course that will teach you way more than this video. You'll learn how to build an actual complex project with React. It's called "Project React" and you can find it at cosden.solutions/project-react. Also, I have a free weekly newsletter called "Import React" with tutorials, news, and cool stuff about React! You can sign up at cosden.solutions/newsletter?s=ytc

  • @master-ik9ro
    @master-ik9ro 2 місяці тому +5

    i really love how the guy's body language communicates the fact that he knows what he is talkig about. his classes feel like they are only ones you will ever truly need

  • @NextGenDevs_
    @NextGenDevs_ 2 місяці тому +5

    I've been a regular viewer of your content, and I really appreciate the way you explain the concepts of React. Your tutorials are always clear and concise. It would be fantastic if you could create a series on NextJS, covering topics like folder structure for large projects and design patterns specific to NextJS. Thanks for all the great content!

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

    Thanks for this video. Was actually watching another video of your earlier today where you referenced folders and best (React) practice.....and now I'm seeing this video. Great timing!!!!!

  • @felipecabreira4321
    @felipecabreira4321 9 місяців тому +3

    Another great content that is actually directly useful in a react application and that any react development can understand from the get go ! Continue with the amazing work my dude :)

  • @icongh1511
    @icongh1511 3 місяці тому

    I have watched a lot tutorials on UA-cam but you are absolutely different. Your explanations a super.

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

    Thanks for the video! As a fresh in React, I really need this. Perfect timing

  • @EvelynOkafor
    @EvelynOkafor 7 днів тому +1

    Thank you, i appreciate your guide.

  • @malekalemam5903
    @malekalemam5903 10 місяців тому +4

    Thanks for the video, it's awesome.
    I think it will be good also to add a folder under the components for layouts since almost every application could have different layouts, so we can have for example BaseLayout/AdminLayout/etc..

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

    I would recommend adding the page name folder under pages and add partials for all sub-components related to that page
    ▼Pages
    ▼ Dashboard
    ▼partials
    Chart.jsx
    Index.jsx

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

      Can you please explain what are these partials? I searched it but partials isn't a apart of React and neithwr is it in Next.js.

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

      all sub-components related to that page@@chinmayghule8272

    • @user-dd7kw3ym5i
      @user-dd7kw3ym5i 6 місяців тому

      @@chinmayghule8272 it is just a name that he decided to give on the folder 😄

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

      @@user-dd7kw3ym5i Thanks for the explanation man. So these partials directory contains components associated with the page which has the same name as the parent directory here, correct?

    • @user-dd7kw3ym5i
      @user-dd7kw3ym5i 6 місяців тому

      @@chinmayghule8272 exactly 💪

  • @Tomiscodin
    @Tomiscodin 8 місяців тому +1

    Super useful video that helped me a lot to summarize thoughts about this topic. Thanks! 👍😎

  • @bogdanandrei9803
    @bogdanandrei9803 10 місяців тому +1

    Found your channel by accident but damn, I love it and you're my new favorite UA-camr. Keep it going!

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

    Thank you for sharing the content! This question had been sit in my head for many years. Now I can finally get rid of this nightmare🥳

  • @abdelhakimkhabir
    @abdelhakimkhabir 2 місяці тому

    00:37 Understanding the folder structure and architecture in React
    01:34 Page folder determines the skeleton of the React application and user navigation.
    03:08 Components folder to hold all UI reusable components.
    04:35 Components/UI folder to hold all small reusable components by other components.
    06:20 Hooks folder.
    07:45 (optional) services/api or services/i18n for multi-language support (internalization), services/stat for state management like redux, 09:09 services/providers for app warppers or for context (rename it to services/context if it's just for context)
    09:50 utils folder for small, useful, Others : utils/helpers.ts or utils/formatters.ts
    12:00 subscribe😃

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

    Thank you. This is vey much informative as a beginner in React, I believe this foundation will help me with my learning journey.

  • @tomasburian6550
    @tomasburian6550 21 день тому

    Great video and just like you, I love the utils folder, because I hate having logic inside the component files, everything looks neat when you can separate things.

  • @tedma4
    @tedma4 8 місяців тому +1

    Using an Atomic Design structure on your components folder helps with keeping things organized.

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

    Best explanation I've ever seen about this topic..Thanks a lot sir 🥰
    Can u plz make a video for react clean architecture

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

    I think adding types(all typescript types can be defined here) folder and constants folder(in case of routes we can use same name through out the application) makes it better. Anyway thanks for sharing your knowledge

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

    Great video
    Fetching, loading state, error state, race condition
    I would have enjoyed to learn about caching requests too, perhaps in its own custom hook

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

      We do this exactly in the React course actually!

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

    Thank you for the useful video. one folder that you haven't included is the test folder and also I think the component should be divided into smart and presentational components.

  • @ScriptChan
    @ScriptChan 2 місяці тому

    Helpful🙌

  • @Pareshbpatel
    @Pareshbpatel 2 місяці тому

    React Folder Structure, clearley explained. Thanks, Darius
    {2024-07-01}

  • @chetandhongade6464
    @chetandhongade6464 6 днів тому

    Thanks bro

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

    Learnt a new thing. Thanks sir.

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

    Thanks boss we really appreciate

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

    Very helpful video, thank you!

  • @aarontrazona1764
    @aarontrazona1764 2 місяці тому

    @cosdensolutions Where did you put large components but not reusable?

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

    Very helpful, thanks❤

  • @celsomomade
    @celsomomade 2 місяці тому

    What't the best aproach to name the ts/tsx files(use camel case, lowcase...)? And when use index.tsx instead of the component name like Button.tsx?

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

    So much helpful, I appreciate this. Thank you

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

    Is the discord link still active?

  • @lyrical6852
    @lyrical6852 11 місяців тому +2

    how about the images? is it on the public folder or assets?

    • @cosdensolutions
      @cosdensolutions  11 місяців тому +1

      that depends on the framework usually and how they serve them

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

    Thanks for this❤

  • @marcogalaxy2944
    @marcogalaxy2944 21 день тому

    one thing i dont understand is how is the form comoneent considered primitive ? doesnt it contain other sub componenets like textinputs , buttons etc , how is it different than a modal component

  • @jay-kv6wn
    @jay-kv6wn Рік тому

    Thank you for this

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

    Thanks a lot❤

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

    Thank you so much

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

    very nice. Where do you like your tests? I have seen a seperate folder for tests that mirrors the app folder structure and I have seen tests folders inside the structure folders.

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

      it really depends on how you want to set it up. I've seen both and both are fine!

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

    Great explanation, thanks!
    I have one question left: What about static files like: fonts, svg, png, favico. Consider a Vite + React + TS app. Should it be placed in the public folder(vite created) or bundled within src/assets(React created)?
    Thank you!

    • @malekboukhari149
      @malekboukhari149 7 місяців тому +1

      If it's a global thing (logo.svg, favicon, font) they can go to the public/assets folder yes. If you have a set of your own icons that you use inside your app (close.svg, avatar.svg) then you could transform them to components and put them inside src/components/icons for example

    • @rick5522
      @rick5522 7 місяців тому +1

      @@malekboukhari149 Thank you! Great answer :)

  • @TemiladeKolawole
    @TemiladeKolawole 2 місяці тому

    How do route through your pages? App.tsx?

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

    thank u soo much bro

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

    Hello, thank you for this really interesting content.
    Where would you advise to locate the unit tests in this architecture ?
    Would you do a separate folder /tests reproducting the tree withs **.specs/test.ts files, or would you put the test files near the .tsx / ts files, like formatting.spec.ts

    • @cosdensolutions
      @cosdensolutions  8 місяців тому +1

      depends on the kinds of tests. If it's e2e integration tests, I'd make a separate folder. If it's unit tests, I'd colocate the test file with the component

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

    Thank you

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

    Thank you so much for this video. It helps a ton!

  • @vijaykumar-ps5pq
    @vijaykumar-ps5pq 3 місяці тому

    I am using almost (80%) same structure❤

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

    is it a good idea to group components in a features folder? For eg. features > todo > components, assets, index.js.
    features > login > components, assets, index.js.

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

    thank youuu.

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

    Thanks

  • @theodorosgeorgitsis5600
    @theodorosgeorgitsis5600 3 місяці тому

    Where do you put the styling of each component?

    • @zeyucui
      @zeyucui 3 місяці тому

      using tailwind

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

    Can you create a video about modular folder structure ?

  • @AmitKumar-cp6mx
    @AmitKumar-cp6mx 9 місяців тому

    I have a question
    On the home page i have different sections
    Should i put each section as component ?

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

      yes, in general you should have your components as much granular as possible, but not "toooooo" granular. Each component should do only one thing. for example here on youtube, i would divide the navbar to 2 or 3 components. One for the logo+ toggling the sidebar, one for the search input + microphone and one for avatar + notifications + create. If for example the search input + microphone component ends up becoming too big because of the logic inside of it, then i would split it into 2 other components, one for the search field and one for the microphone and some sort of context/ store to handle the logic between them.

    • @AmitKumar-cp6mx
      @AmitKumar-cp6mx 7 місяців тому

      @@malekboukhari149 thank you for this suggestion. Now I have one more question should we put these granular components into the same file or in components folder? What would be the best practice?

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

    Can you teach us multiple file uploading in react js

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

    Hi, is it fine if I do this way?
    app
    home
    components // components only used in home
    page.tsx
    auth
    components // components only used in auth
    page.tsx
    ....
    components // I'll store commons/global components
    modals
    cards
    ....

  • @MarijaniNyindo
    @MarijaniNyindo 3 місяці тому

    why isn't nobody talking about the public folder?

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

    Oops :/ I've been literally dividing each section of the site into their own folders and then having that jsx/tsx file in the folder, the css file for that section in that and an images folder within in that for of the section imgs etc etc etc. I thought it was very organized lol but maybe not :/ lol I'll try this.

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

    Where should we locate types and css

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

      depends on the project, not all projects need it so I didn't include it. But you should follow the same patterns and general idea of this video!

  • @netTraverser
    @netTraverser 10 місяців тому

    I like to include a types folder and put my types/interfaces in there in alphabetical order

    • @cosdensolutions
      @cosdensolutions  10 місяців тому +1

      haha nice, same here actually

    • @netTraverser
      @netTraverser 10 місяців тому

      @@cosdensolutions one thing that I really try to wrap my head around, is the thought process before even starting a project. A lot of developers (myself included) love to just jump right into the code with very little planned and just wing it. What is your thought process to design process? Like, how do you choose what DB to use, what Architectures, etc. I would love to see you do a video on that. Maybe a video where you clone a website like Tiktok, but instead of simply cloning it, you can break down each part going over architectures, DB choice/choices, etc. It'll make your channel a lot different from all of these UA-camrs doing flat out clones.

    • @cosdensolutions
      @cosdensolutions  10 місяців тому +4

      @@netTraverser I usually plan quite a lot before doing a project. I'll try to make sure to know what the project will need and what directions it is going in, and then make decisions based off that. I am the type of person who will always advocate for spending more time initially to plan things, because in the long run that will be more beneficial.
      And with regards to DB and things like that, to be fair I usually consult with backend devs as they know more about this than me. I've used mostly relational databases, and sometimes other types, but generally I don't take the lead in those as it's not what I'm concerned about in my day to day job. Sure that is slowly changing now with server components and stuff, but that's still quite a ways from being the norm. So I'm going with the flow

    • @netTraverser
      @netTraverser 10 місяців тому

      @@cosdensolutions Gotcha. Thanks for that. 🙏🏽

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

    if you are affected by OCD like 😂

  • @garcipat
    @garcipat Місяць тому

    Naming things with generic name like utils and helpers is bad practice. Name things on what they do. Formatting is a good example.

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

    where is the client and server folder located?

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

      this was a general structure that would apply to all react, not any specific framework

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

    :)

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

    Nice vídeo

  • @MohamedAdel-du6oj
    @MohamedAdel-du6oj 7 місяців тому

    thanks

  • @sandeshadhikari4785
    @sandeshadhikari4785 10 місяців тому

    thanks