Challenge your expertise with 15 advanced React Native questions and answers. This hard-level quiz covers core concepts like performance, memory leaks, FlatList, SSL pinning, and component management, making it ideal for experienced developers preparing for technical interviews.
Which primary factor leads to performance bottlenecks in React Native applications, especially when dealing with thread communication?
Explanation: The main performance bottleneck in React Native arises from frequent or excessive data passing between the JavaScript and Native threads, which happens via the bridge. This process is costly and slows down interactions. Limited ES6 usage and reliance on functional components are not direct causes of this bottleneck. Unoptimized images may affect rendering but do not directly relate to thread communication.
During iOS development with React Native, which tool is used to detect memory leaks most effectively?
Explanation: On iOS, memory leaks are commonly detected using the Leaks tool within Xcode Instruments, which specifically highlights where memory is not properly released. Safari Web Inspector helps with web debugging, Android Device Monitor is for Android, and React Native Debugger is for JavaScript debugging, not direct memory analysis.
What is the primary advantage of using FlatList over ScrollView for large data sets in React Native?
Explanation: FlatList optimizes rendering by displaying only items visible on the screen, making it highly efficient with large lists. ScrollView, in contrast, renders all children at once, which can degrade performance. FlatList supports both orientations and can render various item types, not just text. Pagination support and image rendering are possible in both.
Why is SSL pinning recommended in React Native mobile apps?
Explanation: SSL pinning links trusted certificates or public keys with an endpoint to prevent man-in-the-middle attacks during communication. It does not relate to bundle size, JS bridges, or image performance. The other options misrepresent the goal of SSL pinning.
How does a controlled component differ from an uncontrolled one in React Native?
Explanation: A controlled component uses React state to manage its input value, while uncontrolled components manage their own state internally. Both types support user input, and neither inherently requires Redux. Controlled components may re-render often based on state changes.
Which coding mistake most commonly causes memory leaks in React Native?
Explanation: Failing to remove listeners or timers during unmounting can result in memory that is never freed, causing leaks. Functional components and PropTypes are not directly related to leaks, and useMemo, while misused, does not typically result in memory leaks if cleaned up appropriately.
Why should developers minimize the number of passes over the React Native bridge?
Explanation: Each transfer over the React Native bridge introduces latency and processing cost, creating noticeable lags. Passes do not facilitate garbage collection, have no effect on code splitting, and do not disable touch events. The other options describe incorrect effects.
Which toolset is typically used to identify memory leaks in React Native apps on Android devices?
Explanation: Android Device Monitor along with Profiler tools are standard for analyzing memory usage and leaks on Android. Chrome tools are tailored for web, Xcode is for iOS, and npm audit checks dependencies for vulnerabilities but not runtime memory leaks.
Which prop should be set in FlatList for better performance when each item has a fixed height?
Explanation: Setting the getItemLayout prop allows FlatList to compute positions and skip measurement calculations, making scrolling more efficient with uniform item heights. extraData is used for re-render control, scrollEnabled toggles scrolling, and keyboardShouldPersistTaps relates to keyboard interactions.
In a class component, which lifecycle method is best suited for unsubscribing from timers or listeners to prevent leaks in React Native?
Explanation: componentWillUnmount is specifically designed for clean-up tasks like removing timers or listeners, preventing leaks. componentDidMount handles setup, shouldComponentUpdate determines re-rendering, and componentDidCatch deals with error boundaries, not clean-up.
What happens if the pinned certificate or public key changes unexpectedly in SSL pinning within a React Native app?
Explanation: When the pinned certificate or key changes, SSL pinning mechanisms block the connection to prevent security risks. The connection is not silently accepted, and network protocols are not downgraded. App data remains secure; it will not be shown in plaintext due to a pinning mismatch.
What is a direct consequence of using ScrollView instead of FlatList for long lists with thousands of items?
Explanation: ScrollView renders all items in memory, which with thousands of elements can lead to high memory and poor performance. It does not enhance battery efficiency or text antialiasing, nor does it support automatic pagination.
Which aspect of JavaScript garbage collection can unintentionally cause memory leaks in React Native?
Explanation: Variables referenced by closures may persist even after being logically unused, preventing garbage collection and causing leaks. Stateless components and inline styles are not linked to leaks, and importing large assets mainly affects loading time, not garbage collection.
Why might relying solely on uncontrolled components in React Native lead to unpredictable input behavior?
Explanation: Uncontrolled components manage their own state, making it difficult for React to keep track of changes triggered externally. They do not force constant rerender, and there's no exclusive threading or useCallback requirement for using them.
If a React Native app frequently animates hundreds of elements by updating their properties from JavaScript, what performance issue is likely to occur?
Explanation: Updating many properties on the JS side for animation causes frequent passes over the bridge, quickly saturating it and causing animation lag. Instant animations are unlikely, static asset loading does not cause this type of lag, and native module registration is unrelated.