Question from the React Native (Legacy) test

Which of the following code snippets will print 'Hello World' to the console?

Hard

### Si je dois conditionner mon code en fonction d'iOS ou d'Android, comment dois-je procéder ?

Code A:
* fichier index.ios.js
import React from "react";
class MyIosComponent extends React.Component {
      render () {
            return (<Element>I’m in iOS</Element>);
      }
}
* fichier index.android.js
import React from "react";
class MyAndroidComponent extends React.Component {
      render () {
            return (<Element>I’m in Android</Element>);
      }
}

Code B:
import React from "react";
import {Platform} from "react-native";
class MyComponent extends React.Component {
      render () {
      		return device.platform === "iOS"
          	? 	(<Element>I’m in iOS</Element>)
	          :	(<Element>I’m in Android</Element>)
      }
}

Code C:
import React from "react";
import {Platform} from "react-native";
class MyComponent extends React.Component {
      render () {
            return Platform.select({
	            ios: () => (<Element>I’m in iOS</Element>),
	            android: () => (<Element>I’m in Android</Element>)
            })
      }
}

Author: Victor SabatierStatus: PublishedQuestion passed 413 times
Edit
1
Community EvaluationsNo one has reviewed this question yet, be the first!