React Native Questions
Warm up for your React Native interview with most asked questions and answers for junior, mid, and senior roles.
How are props and state different?
Show AnswerHide Answer
Props are immutable. State is mutable.
How are Hot Reloading and Live Reloading in React Native different?
Show AnswerHide Answer
Hot Reloading
- It only reloads the file that changed
- The state of your app is maintained.
- Modify your code without any delay.
Live Reloading
- It reloads the whole app.
- The state of your app is reseted.
What is AppRegistry?
Show AnswerHide Answer
AppRegistry is the entry point to your React Native application. It is like the root component of your application.
What does StyleSheet.create do and why is it useful?
Show AnswerHide Answer
StyleSheet.create is used to create a stylesheet object that you can use to style your components.
It's useful because moving your styles to a stylesheet object makes it easier to manage, reuse styles, and improve performance.
What is AsyncStorage?
Show AnswerHide Answer
AsyncStorage is a simple, unencrypted, asynchronous, persistent, key-value storage system that is global to the app.
List some packages that implement native modules for both iOS and Android
Show AnswerHide Answer
- Camera
- Bluetooth
- Contacts
- Date Picker
- Image Picker
List some ways you can optimize an application
Show AnswerHide Answer
- Use FlatLIst or SectionList to render large lists.
- Remove console statements
- Memoize expensive computations (memo HOC, useCallback and useMemo)
- Cache image locally
- Use WebP image format
- Use Native driver with Animated API
- Use Hermes and ProGuard
What is props drilling?
Show AnswerHide Answer
Prop drilling is the term for passing data through several nested children components. It can cause issues with component reusability and app performance.
How do you handle different screen sizes in React Native?
Show AnswerHide Answer
You can use PixelRatio which gives you access to the device's pixel density and font scale, so you can use it to handle different screen sizes, but there is a couple of libraries that provide some tools to handle responsiveness, like:
- react-native-responsive-screen
- react-native-responsive-fontsize
- react-native-auto-size-text
What are hooks in React Native and what are some of the advantages?
Show AnswerHide Answer
Hooks allow you to write functions that can be used in React components. They are a way to write code in a modular and reusable way, using all the React features.
What are Container/Smart components?
Show AnswerHide Answer
Container components are the ones that manage the state of the application. They receive the props and pass them to the presentational components.
What are Presentational/Dumb Components?
Show AnswerHide Answer
Presentational components are the ones that receive the props and render the UI. They don't manage or change the state of the application.
How useEffect works in React Native?
Show AnswerHide Answer
It is a hook that is called after the component is rendered for the first time, before the component is unmounted, and also when some of the props in the dependency array changes.
What is the significance of keys in React Native?
Show AnswerHide Answer
It helps React identify which items have changed, added, or removed, increasing its performance when diffing between the virtual and real DOM
How to use animations in React Native?
Show AnswerHide Answer
You can implement animations in React Native using the Animated API or react-native-reanimated library
What is Redux and why it is used?
Show AnswerHide Answer
Redux is a state management pattern. It helps you manage the application state, synchronizing the application's state between multiple parts of the application.
It has three main parts:
- Reducers: A function that returns the next state given the current state and an action to handle.
- Actions: An object that describes an event. It has a type property that defines the event, and a payload property that contains the data associated with the event.
- Store: A single source of truth for the application state. It is the only source of truth for the application state.
How to use SVG in React Native?
Show AnswerHide Answer
You can use SVG in React Native using the react-native-svg library
What is Expo?
Show AnswerHide Answer
Expo is a platform for building native apps for iOS and Android. It provides a set of tools that simplify the development of React Native apps.
How do you debug React Native apps?
Show AnswerHide Answer
You can use Chrome Dev Tools, react-native-debugger, Flipper or Reactotron to debug React Native apps.
What is the difference between a functional component and a class component?
Show AnswerHide Answer
A functional component is a function that returns a React element. A class component is a class that extends React.Component.
What is the difference between useState and useReducer?
Show AnswerHide Answer
useState is a hook that allows you to manage the state of a component. It is a function that returns an array with two elements: the current state and a function to update the state, and it uses useReducer under the hood.
useReducer gives you more control over the state of your component. It takes a reducer function and initial state as arguments and returns the state and dispatch method.
What is Gesture Responder System?
Show AnswerHide Answer
The gesture responder system manages the lifecycle of gestures in your app. A touch can go through several phases as the app determines what the user's intention is.
For example, the app needs to determine if the touch is scrolling, sliding on a widget, or tapping. This can even change during the duration of a touch. There can also be multiple simultaneous touches.