Question 1. What is state and props in React-Native?
Answer:- State and props, both are key concept of react-native. In react-native, components is controlled by two types of data.
1 . State:- The data of component, that is going to change is state. State is mutable that means state can be updated. state can be initialized in constructor and when we want to change call setState.
Example:-
import React, { Component } from ‘react’;
import {
AppRegistry,
Text,
TouchableOpacity
} from ‘react-native’;
export default class Logicstime extends Component {
constructor(props) {
super(props);
this.state = {
text: ‘State Example’,
};
}
render() {
return (
this.setState({text: “text change of state”})}> this.state.text
);
}
}
AppRegistry.registerComponent(‘Logicstime’, () =>Logicstime);
1 . props :- In react, components can be customized with props. These props are immutable that is why they are fixed throughout the lifetime of a component.
Example:-
import React, { Component } from ‘react’;
import { AppRegistry,, Text, View } from ‘react-native’;
class Welcome extends Component {
render() {
return (
{this.props.welcomeText}
);
}
}
class PropsExample extends Component {
render() {
return (
);
}
}
AppRegistry.registerComponent(‘PropsExample’, () =>PropsExample);
Question 2:- What is difference between state and props ?
Answer:- 1. state are mutable that means it can be updated in future while props are immutable that means it cannot be updated in future.
- Props are passed to the child component within the render method of the parent Component.
Question 3:- Which event is triggered for input field to submit using mobile keyboard.
Answer:- onSubmitEditing
Ques 4:- What is advantages of using react-native instead of native language?
Answer:- 1. Platform independent.
- Reusable Components.
- React-Native compatible with third party plugin, uses less memory, hot reloading, and smoother experience.
- Learn once, write anywhere.
- More predictable coding.
- Declarative style.
Click here for more details.
Question 5:- How do we make release apk for android in react-native?
Answer:- 1. First generate Generating a signing key from following command.
$ keytool -genkey -v -keystore my-release-key.keystore -alias my-key-alias -keyalg RSA -keysize 2048 -validity 10000
- Setting up gradle variables.
- Generating the release APK
$ cd android && ./gradlew assembleRelease
Click here for more details
Question 6:- If your application is released, How can you update in front of your end users instantly, without upload new apk on playstore.
Answer:- Using the react-native-code-push which helps get product improvements in front of your end users.
Click here for more details.
Question 7:- How can we get the device info and mobile number of device in react-native.
Answer:- There are plugin like react-native-device-info which provides device info as well as mobile numbers.
Question 8:- Life cycle of react-native components.
Answers:- There are following life cycle structure. Click here for more details
Question 9:- Command for create new react-native project.
Answer:- react-native init ProjectName
Question 10:- Command to run the react-native project.
Answer:- react-native run-android
Question 11:- What is difference between react-native and reactjs.
Answer:- Reactjs is javaScript library used to develop web application in HTML5 where as react-native used to create native mobile app which is cross platform and can be run android as well as IOS.