Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

react-native init doesn't make src folder

Tags:

react-native

I'm following this tutorial: https://docs.realm.io/sync/getting-started-1/react-native-quick-start/step-1-query-based-sync#step-4-create-a-constants-file-and-set-the-realm-instance-address

Many documents including this tutorial refers a src folder, but when I create a React Native project with a command like react-native init MyProject, it doesn't create src folder. Why is that?

Following is my folder structure:

├── App.js
├── android
├── app.json
├── index.js
├── ios
├── node_modules
├── package.json
└── yarn.lock
like image 575
alanhchoi Avatar asked Dec 22 '18 16:12

alanhchoi


People also ask

Why SRC and public folder is not created while installing react?

Because the global installs of create-react-app are no longer supported you might have it installed on your machine, thus have the old version running whenever you try to npx create-react-app .

What is src folder in react native?

src(folder) In simplest form it's our react app folder i.e. containing components, tests, css files etc.

How do I create a react native app directly in the current folder?

Use a dot for the path to create a React app in the current directory, e.g. npx create-react-app . or npx create-react-app . --template typescript for TypeScript projects. Make sure your folder name doesn't contain special characters, spaces or capital letters.


1 Answers

because react-native-cli do not provide src folder. its up to you, how you design or architect your app. directory structures are upto you and you need to write code accordingly. Generally project specific code always kept in src folder. In your case, there is just one component and App.js is the only file that holds the entire code. but as there will many screens/components you will find it unmanageable. for sake of modularity, src folder is made and used.

App
|
|--src
    |
    |--assets
    |--components
    |--screens
          |
          |--loginScreen.jsx
          |--homeScreen.jsx
like image 115
Anshul Masne Avatar answered Oct 07 '22 22:10

Anshul Masne