Learn React-native basics

Before start programming on react-native, we have to understand the basics of react-native like React-native folder structure, imports, methods

React-native from basics, folder structure, code structure, imports, methods

To create new project use following command:

 

Here is my React-native folder structure

  • Android folder:- This folder contains Android Java code
  • IOS folder:- This folder contains IOS code
  • Node_modules folder:- This contains nodeJS modules also contain react-native libraries which we will be going to install in future
  • App.json:- This file is used to configuring parts of your app that don’t belong in code.
  • index.js file:- This is an entry file in your app

This file automatically generates, as we can see in above screenshot it uses AppRegistry from react-native and register it with App.js file which is imported as import App from ‘./App’; and register as follows: AppRegistry.registerComponent(‘MySampleApp’, () => App);

  • package.json:- This file usually place in project root folder, it contains various metadata related to project, the first section contains App name, version, scripts the second section contain all dependencies relevant to project. Next, to that contain devDependances and its versions

  • App.js file:- You can put your code into this file, also you can declare different screens on this page using Stack Navigation

Let’s talk about react-native code structure 

1.React-native imports

consider above App.js code, firstly there are imports at the top, we will add another external components or libraries as well as other custom views in this section

View is in another directory and you want to access the file from root folder then imports as like follow:

if your view is in the same directory and you are not in root folder then imports as like follow:

if your view is in another directory then and you are not in root folder imports as like follow:

2. React-native main call

All code in js file is inside of the main call make sure this class name is same as the class file name we can add our methods inside this class this class contain one render method which renders our code and display data using return method

from next article, we will start coding i.e how to use Stack navigation, how to make API call how to parse data, how to transfer data from one screen to another screen also learn react UI components.

6 Replies to “Learn React-native basics”

  1. Hey very cool blog!! Man .. Beautiful .. Amazing .. I will bookmark your site and take the feeds also…I’m happy to find so many useful info here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .

Leave a Reply

Your email address will not be published. Required fields are marked *