Issue
As GFG repo continues to grow larger, the current folder structure doesn't seem be as clear and direct to a developer.
As a result, differentiating from a dummy component from a page component is difficult.
Suggestion
src/components:
- Reserved only for
dummy components
- No api/business logic should be found within such components
- Components here should be generic and not tied to any particular page
src/pages:
- Reserved only for
page components
- Business logic/Apis can be found within the components here
src/pages/{pageName}/index.js
- entry point for that particular page
src/pages/{pageName}/components
- Components that belong to this
page components should live within here
- Have a
index.js that exports all the components within, this is done so that importing components can be in a single line
- This can be a recursive folder structure.
- Eg:
src/pages/components/RegisterDonor/index.js can have src/pages/components/RegisterDonor/components/RegisterCard/index.js
src/pages/{pageName}/utils
- utils that belong to this page should live here
src/pages/{pageName}/constants
- constants that belong to this page should live here
src/utils
- Reserved only for generic utils
src/constants
- Reserved only for generic constants
Additionally, try to group the import statements based on their groups if possible, i.e.
// components
import Header from '@components/header';
import SessionProvider from '@components/session/modules/SessionProvider';
import ContactUsPage from '@pages/contactUs';
// constants and utils
import { WISHES } from '@constants/search';
import { isAuthenticated } from '@utils/authentication/authentication';
// dynamic imports
const TopNavigationBar = dynamic(() => import('@components/navbar/modules/TopNavigationBar'), { ssr: false });
const BottomNavigation = dynamic(() => import('@components/navbar/modules/BottomNavigation'), { ssr: false });
const Footer = dynamic(() => import('@components/footer/Footer'), { ssr: false });
Template to copy
// components
// hooks
// constants and utils
// dynamic imports
Benefits
- Separation of concern from each page. As such, we can introduce new UI libraries for individual pages without worrying that it might affect other pages.
- Easier to scale in terms of adding new pages
Downsides
- Potentially might have duplicated codes
Issue
As GFG repo continues to grow larger, the current folder structure doesn't seem be as clear and direct to a developer.
As a result, differentiating from a
dummycomponent from apagecomponent is difficult.Suggestion
src/components:dummycomponentssrc/pages:pagecomponentssrc/pages/{pageName}/index.jssrc/pages/{pageName}/componentspagecomponents should live within hereindex.jsthat exports all the components within, this is done so that importing components can be in a single linesrc/pages/components/RegisterDonor/index.jscan havesrc/pages/components/RegisterDonor/components/RegisterCard/index.jssrc/pages/{pageName}/utilssrc/pages/{pageName}/constantssrc/utilssrc/constantsAdditionally, try to group the import statements based on their groups if possible, i.e.
Template to copy
Benefits
Downsides