React Native

Platform-Specific Code

Platform.OS, Platform.select, .ios.js/.android.js, native APIs access

18 câu hỏi phỏng vấn·
Mid-Level
1

Which property should be used to determine if the application is running on iOS or Android?

Câu trả lời

Platform.OS returns a string indicating the current operating system: 'ios' for iOS and 'android' for Android. This property is the most direct method to check the running platform and adapt the application behavior accordingly.

2

What is the correct syntax to use Platform.select to apply different styles based on the platform?

Câu trả lời

Platform.select accepts an object with 'ios', 'android' and optionally 'default' keys. This method allows defining platform-specific values in a declarative and concise way, which is particularly useful for styles and configurations.

3

How to create a component with different implementations for iOS and Android using file extensions?

Câu trả lời

React Native automatically detects files with .ios.js and .android.js extensions during bundling. By creating two files like Button.ios.js and Button.android.js, importing 'Button' will automatically load the appropriate version based on the platform, without explicit conditions in the code.

4

Which Platform property allows checking the operating system version?

5

What is the main advantage of using file extensions (.ios.js/.android.js) compared to Platform.select?

+15 câu hỏi phỏng vấn

Nắm vững React Native cho lần phỏng vấn tiếp theo

Truy cập tất cả câu hỏi, flashcards, bài kiểm tra kỹ thuật, bài tập code review và mô phỏng phỏng vấn.

Bắt đầu miễn phí