React Native is a framework created by Facebook that is used for building native apps using React. It is mainly used for developing applications for Android, iOS, and Web. It an open-source framework. So, today we will be checking out the 13 most asked React Native questions. 13 Most Asked React Native Questions 1. What is the difference between React Native and React? Answer: is a JavaScript library, supporting both front-end web and being run on a server, for building user interfaces and web applications. is a mobile framework that compiles to native app components, allowing you to build native mobile applications for different platforms (iOS, Android, and Windows Mobile) in JavaScript that allows you to use ReactJS to build your components, and implements ReactJS under the hood. Both follow the JSX syntax extension to JavaScript. Both are open-sourced by Facebook. ReactJS React Native 2. What is the difference between using constructor vs getInitialState in React / React Native? Answer: The two approaches are not interchangeable. You should initialize state in the constructor when using ES6 classes, and define the method when using . . getInitialState React.createClass See the official React doc on the subject of ES6 classes { (props) { (props); .state = { }; } } . class MyComponent extends React Component constructor super this /* initial state */ is equivalent to MyComponent = React.createClass({ getInitialState() { { }; }, }); var return /* initial state */ 3. How to fix error while running React Native app from terminal (iOS)? You can check out this link ( ). It appears to be a problem with the location of . In Xcode, select the Xcode menu, then Preferences, then Locations tab. Select your Xcode version from the dropdown and exit Xcode. Answer: Running react-native run-ios occurs an error? Command line tools Alternative Answer: You may need to install or set the location of the . Xcode Command Line Tools Via command line If you have Xcode downloaded you can run the following to set the path: sudo xcode-select -s /Applications/Xcode.app If the command line tools haven’t been installed yet, you may need to run this first: xcode-select --install You may need to accept the Xcode license before installing command-line tools: sudo xcodebuild -license accept 4. How to fix error “Unable to load script from assets index.android.bundle” on Windows? Answer: This will help you to resolve the problem in the following steps. issue (in the project directory) mkdir android/app/src/main/assets react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res react-native run-android You can automate the above steps by placing them in part of like this: scripts package.json : "android-linux" "react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res && react-native run-android" Then you can just execute from your command line every time. npm run android-linux Alternative Answer: If You are running your application on a physical device and getting this error unable to load script assets index.android.bundle from try running the command: adb reverse tcp: tcp: 8081 8081 5. How to fix error “React Native android build failed. SDK location not found”? Answer: Go to the directory of your react-native project android/ Create a file called with this line: local.properties sdk.dir = USERNAME/Library/Android/sdk /Users/ Where is your macOS username. USERNAME Alternative Answer: Go to your React-native Project -> Android Create a file local.properties Open the file paste your Android SDK path like below - In Windows - In macOS - In Linux sdk.dir = C:\\Users\\USERNAME\\AppData\\Local\\Android\\sdk sdk.dir = /Users/USERNAME/Library/Android/sdk sdk.dir = /home/USERNAME/Android/Sdk Replace USERNAME with your user name. Now, Run the in your terminal. react-native run-android 6. How to hide keyboard in React Native? The problem with keyboard not dismissing gets more severe if you have , as there is no way to dismiss it. Answer: keyboardType='numeric' Replacing View with ScrollView is not a correct solution, as if you have multiple s or s, tapping on them while the keyboard is up will only dismiss the keyboard. textInput button The correct way is to encapsulate View with and calling . TouchableWithoutFeedback Keyboard.dismiss() You can now use with to only dismiss the keyboard when the tap is not handled by the children (ie. tapping on other textInputs or buttons) If you have ScrollView keyboardShouldPersistTaps='handled' <View style={{ : }}> flex 1 < = /> TextInput keyboardType 'numeric' </ > View Change it to <ScrollView contentContainerStyle={{ : }} keyboardShouldPersistTaps= > flexGrow 1 'handled' < = /> TextInput keyboardType 'numeric' </ > ScrollView or {Keyboard} <TouchableWithoutFeedback onPress={Keyboard.dismiss} accessible={ }> <TextInput keyboardType='numeric'/> </View> import from 'react-native' false < = }}> View style {{flex: 1 </ > TouchableWithoutFeedback You can also create a Higher Order Component to dismiss the keyboard. React ; { TouchableWithoutFeedback, Keyboard, View } ; DismissKeyboardHOC = { ( <Comp {...props}> {children} </Comp> ); }; DismissKeyboardView = DismissKeyboardHOC(View) import from 'react' import from 'react-native' const ( ) => Comp return ( ) => { children, ...props } < = = > TouchableWithoutFeedback onPress {Keyboard.dismiss} accessible {false} </ > TouchableWithoutFeedback const Simply use it like this ... render() { <DismissKeyboardView> } < = /> TextInput keyboardType 'numeric' </ > DismissKeyboardView Note: The is required to make the input form continue to be accessible through VoiceOver. accessible={false} Alternative Answer: This got updated . No more hidden tricks. and documented { Keyboard } Keyboard.dismiss() import from 'react-native' // Hide that keyboard! https://github.com/facebook/react-native/pull/9925 7. How to fix error “Application has not been registered”? Answer: It is an error caused by not matching the name of project and your registered component. You have inited project with one name, i.e. react-native init AwesomeApp But in your index.ios.js file, you register other component AppRegistry.registerComponent( , () => Bananas); 'Bananas' When it be must AppRegistry.registerComponent( , () => Bananas); 'AwesomeApp' Try to fix it. Alternative Answer: Most of the time the problem is that you have another (i.e. React Native Packager) server running either on another terminal or another tab of TMUX (if you are using TMUX). react-native start You need to find that process and close it, so after running for instance, it will establish a new packager server that registered for that specific application. Just find that process using: react-native run-ios ps aux | grep react-native Find the process id (PID) and kill the packager process using command (e.g. ). You should find the app in macOS, not sure about the other operating systems. kill kill -9 [PID] launchPackager.command Then try to run the (or android) again. You should be able to see the new path after running the new packager server, e.g.: run-ios Looking JS files /Users/afshin/Desktop/awesome-app for in 8. How to add icons to the React Native app? Answer: iOS Icons Set in . AppIcon Images.xcassets Add 9 different size icons: - 29pt - 29pt*2 - 29pt*3 - 40pt*2 - 40pt*3 - 57pt - 57pt*2 - 60pt*2 - 60pt*3. Images.xcassets will look like this: Android Icons Put in folders . - 72*72 . - 48*48 . - 96*96 . - 144*144 . - 192*192 . ic_launcher.png [ProjectDirectory]/android/app/src/main/res/mipmap-*/ ic_launcher.png in mipmap-hdpi ic_launcher.png in mipmap-mdpi ic_launcher.png in mipmap-xhdpi ic_launcher.png in mipmap-xxhdpi ic_launcher.png in mipmap-xxxhdpi Update 2019 Android The latest versions of React Native also supports the round icon. For this particular case, you have two choices: In each mipmap folder, add additionally to the file also a round version called with the same size. a. Add round icons: ic_launcher.png ic_launcher_round.png Inside remove the line and save it. b. Remove round icons: yourProjectFolder/android/app/src/main/AndroidManifest.xml android:roundIcon="@mipmap/ic_launcher_round" Otherwise, the build throws an error. 9. How to combine multiple inline style objects? Answer: If you’re using React Native, you can use the array notation: <View style={[styles.base, styles.background]} /> Check out about this in detail. blog post Alternative Answer: You can use the spread operator: <button style={{...styles.panel.button,...styles.panel.backButton}}>Back< /button 10. How to change the default iOS simulator device? Answer: Specify a simulator using the flag. --simulator These are the available devices for iOS 12.0: react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= react-native run-ios --simulator= "iPhone 5s" "iPhone 6" "iPhone 6 Plus" "iPhone 6s" "iPhone 6s Plus" "iPhone 7" "iPhone 7 Plus" "iPhone 8" "iPhone 8 Plus" "iPhone SE" "iPhone X" "iPhone XR" "iPhone Xs" "iPhone Xs Max" "iPad Air" "iPad Air 2" "iPad" "iPad Pro" "iPad Pro" "iPad Pro" "iPad Pro" "iPad" List all available iOS devices: xcrun simctl list devices There is currently no way to set a default. React Native Docs: Running On Simulator Alternative Answer: You can also use for this by adding an entry to the element of your file. npm scripts package.json E.g. : "launch-ios" "react-native run-ios --simulator \"iPad Air 2\"" Then to use this: npm run launch-ios 11. How to do logging in React Native? Answer: works. console.log By default on iOS, it logs to the debug pane inside Xcode. From the IOS simulator press ( ) and press . This will open a resource, on the localhost. From there use Chrome Developer tools javascript console to view . ⌘+D Remote JS Debugging http://localhost:8081/debugger-ui console.log Alternative Answer: Use etc. console.log, console.warn As of React Native 0.29, you can simply run the following to see logs in the console: $ react-native log-ios $ react-native log-android 12. How to insert a line break into a <Text> component in React Native? Answer: This should do it: <Text> Hi~{ } is a test message. < "\n" this /Text> Alternative Answer: You can also do: <Text>{ }< ` Hi~ this is a test message. ` /Text> By doing this, you don’t have to insert stuff within the string; just wrap it once and it keeps all your line-breaks. 13. What is the difference between react-native-firebase and react-redux-firebase? Answer: Main difference: – for using Firebase with Redux react-redux-firebase – for using Firebase JS API with react-native react-native-firebase actually . provides the while using native-modules under the hood, meaning you can provide that as your Firebase instance to like so: react-redux-firebase supports using react-native-firebase react-native-firebase Firebase JS API react-redux-firebase { compose, createStore } ; RNFirebase ; { getFirebase, reactReduxFirebase } ; thunk ; makeRootReducer ; reactNativeFirebaseConfig = { : }; reduxFirebaseConfig = { : , }; (initialState = { : {} }) => { firebase = RNFirebase.initializeApp(reactNativeFirebaseConfig); store = createStore( makeRootReducer(), initialState, compose( reactReduxFirebase(firebase, reduxFirebaseConfig), ) ); store; }; import from 'redux' import from 'react-native-firebase' import from 'react-redux-firebase' import from 'redux-thunk' import from './reducers' const debug true const userProfile 'users' // save users profiles to 'users' collection export default firebase // initialize firebase const const // pass initialized react-native-firebase app instance // applyMiddleware can be placed here return This setup and more are covered in the . react-native recipes section of the docs These are the 13 most commonly asked React Native questions. If you have any suggestions or any confusion, please comment below. If you need any help, we will be glad to help you. Hope this article helped you. In Conclusion This post was originally posted on . DevPost by Truemark Previously published at https://thedevpost.com/blog/13-most-asked-react-native-questions/