React Native for Beginners

React Native for Beginners

Share

This is an Education Website Where you can get Basic Traning of React Native and you can master within 3 months. All Courses Are Free of Cost.

22/01/2022

How to Improve the Performance of React Native App?

There are so many ways to do this but here are few most preferred ways:-

Use of shouldComponentUpdate method of react-native lifecycle
Use Pure Components of React
Use Memo from Hooks API
Build the module with native whenever it is possible
Remove the console logs before building the application
Reduce Application size
Use of shouldComponentUpdate
Using shouldComponentUpdate method, we can reduce unnecessary re-rendering of components.

shouldComponentUpdate returns the boolean value and according to that components will rerender. For example, if it returns true then it will rerender and if it returns false then it will not rerender component.

So, on state update or on new props to the component this method will be called with two arguments called nextState and nextProps. So, you can compare the new props and state with the previous ones. And according to your business logic requirements, you can use the boolean to render the component again.
Use Memo from Hooks API
React Hooks provide the lifecycle of components to functions.

Memo from react helps to do a shallow comparison on upcoming changes. So, it allows re-rendering functions only if the props get changed.

Build the module with the native driver whenever it is possible
Here, We are not talking about not using React Native. Sometimes, it happens that we have to use some features which can be done by the native more efficiently. At that time, we have to build that module in native one and can use the feature from the React Native by creating a bridge.
Remove the console logs before building the application
It has been identified that the console logs are taking some amount of time for logging purposes. So, it is good to use at the time of development but in the production build, it should be removed which will help to improve the performance of the app which you will realize while using it.

Reduce Application size
In React Native, you use external libraries and components form libraries so it impacts application size.

To reduce the size, you have to optimize the resources, use ProGaurd, create different app sizes for different device architectures, and make sure to compress the graphics elements, i.e. images.

The components on the JavaScript side use a bridge to communicate with the Native side. Reduce the load on the bridge and improve the app’s performance.

19/01/2022
31/05/2021

merge arrays

var localcontacts = [
{id:1, number:"03408906107", name:"Aftab telenor", localuri:"photolocaluri"},
{id:2, number:"03179608039", name:"Aftab Zong", localuri:"photolocaluri"},
{id:3, number:"03010183699", name:"Abid", localuri:"photolocaluri"},
{id:4, number:"03408906106", name:"Aqeel", localuri:"photolocaluri"},
//{id:5, number:"0340890615", name:"Saad", localuri:"photolocaluri"},
];
var servercontacts = [
{id:1, snumber:"03408906107", sname:"Aftab telenor", serveruri:"photolocaluri"},
{id:2, snumber:"03179608039", sname:"Aftab Zong", serveruri:"photolocaluri"},
{id:3, snumber:"03040195649", sname:"Abid", serveruri:"photolocaluri"},
{id:4, snumber:"03408906106", sname:"Aqeel", serveruri:"photolocaluri"},
{id:5, snumber:"0340890615", sname:"Saad", serveruri:"photolocaluri"},
];
function mergeArrayObjects(arr1,arr2){
return arr1.map((item,i)=>{
if(arr2[i]){
if(item.number === arr2[i].snumber){
//merging two objects
return Object.assign({},item,arr2[i])
}
}else{
return Object.assign({},item)
}
})
}

console.log(mergeArrayObjects(localcontacts,servercontacts));

07/04/2021

How to calculate Time Difference in days. Here is Code.

import React, { useEffect } from 'react'
import {View,TouchableOpacity, Text} from 'react-native'
const DatetimeDiff = () =>{
const timediff = () => {
console.log(new Date("April 30, 2021").getTime())
var msDiff = new Date("April 30, 2021").getTime() - new Date().getTime(); //Future date - current date
var daysTill30June2035 = Math.floor(msDiff / (1000 * 60 * 60 * 24));
console.log(daysTill30June2035);
}
return(

{ timediff()}} style={{height:50, justifyContent:"center", alignItems:"center", width:200, borderRadius:10, backgroundColor:" "}}>
Caluate Time


)
}

export default DatetimeDiff;

Want your school to be the top-listed School/college in Rawalpindi?

Click here to claim your Sponsored Listing.

Location

Telephone

Website

Address


Bahira Town Plaza 160
Rawalpindi

Opening Hours

Monday 09:00 - 17:00
Tuesday 09:00 - 17:00
Wednesday 09:00 - 17:00
Thursday 09:00 - 17:00
Friday 09:00 - 17:00
Saturday 09:00 - 17:00