Reputation: 34507
I am new in react-native
. I am trying to develop my first app in react-native
. I want to know what is the correct project structure for developing react-native
apps.
As of now, I have created component
in root folder. I want to know what approach should I take for defining model, utils, webservice urls in what structure.
Does it has some kinda framework as like express
for creating project structure in nodejs
.
Upvotes: 0
Views: 380
Reputation: 10857
From my experience in building quite a large app using react-native. I have followed this approach and it scales pretty well for a team of 5+ people working on it .
App folder : : In this folder I keep all the files/folders related to app. Do not add anything in root folder. the less convoluted the root folder is the better for new person to get started.
uicomponents : The uicomponents folder holds all the generic controls that app needs. eg : Dropdowns, sliders, buttons, checkboxed. You can avoid this if you are using a external lib.
components : This folder holds folders for each section of screen. I call it modules for app. Each module is specific area of app, namely : HomePage, UserData, Settings so on so forth. This varies from genre of the app. My happens to be enterprise app, So I have folders for each module for an app.
Utils : I am big fan of keeping utils at one place. Things like text formatters, Db handers, Oauth Handlers and so on.
Stores, Dispatchers : Anything related to flux, redux can go in there.
In general the app has to be broken down in appropriate folders and files. One specific part of the app or module as I say has to have its own folder. All the files needed by him has to be in it. This makes it easy to be maintained and reasoned about.
Avoid duplicating code from beginning. Keep reusable things in Utils. All control related components (inputs, buttons, checkboxes) at one place.
Always keep styles at one place. Use constant variables for colors, this makes making changes very easy. The constant file holds colors.
Upvotes: 3