Hard
For the following component, which modified version allows it to be used in a React Native project?
Example:
const MyComponent = () => (
<div>
My Component
<img src="https://facebook.github.io/react-native/img/header_logo.png"/>
</div>
)
Code A:
import React from 'react'
const MyComponent = () => (
<div>
My Component
<img src="https://facebook.github.io/react-native/img/header_logo.png"/>
</div>
)
Code B:
import React from 'react'
import {Div, Img} from 'react-native'
const MyComponent = () => (
<Div>
My Component
<Img src="https://facebook.github.io/react-native/img/header_logo.png"/>
</Div>
)
Code C:
import React from 'react'
import {View, Image} from 'react-native'
const MyComponent = () => (
<View>
My Component
<Image source={{uri: "https://facebook.github.io/react-native/img/header_logo.png"}} />
</View>
)
Code D:
import React from 'react'
import {View, Text, Image} from 'react-native'
const MyComponent = () => (
<View>
<Text>
My Component
</Text>
<Image source={{uri: "https://facebook.github.io/react-native/img/header_logo.png"}} />
</View>
)
Edit
-2
Community Evaluations
Ahmed
18/02/2022
L"option C ici est totallement incorrecte car on peut pas render un text dehors d'une balise Text
Vincent Cotro
21/02/2022
Hello Ahmed, sauf erreur il est possible de mettre du texte en dehors d'une balise texte. Je viens de tester sur un simulateur : https://snack.expo.dev/. Par contre il y a une erreur de syntaxe sur la réponse C que je vais corriger. Merci pour ton message.
Auteur anonyme
14/04/2022
Ca fonctionne peut-être sur le snack, mais l'exécution en local via 'expo start' donne une erreur : "Text strings must be rendred within a <Text> component.". Je ne pense pas qu'il faille considérer la réponse C comme juste.
Similar QuestionsMore questions about React Native
5
Write a React Native animation that spins an image.1
What is the output of the following code?
const App = () => {
const [count, setCount] = useState(0);
return ({
<Text>
The count is {count}
</Text>
<Button onPress={() => setCount(count + 1)}>
Increase
</Button>
});
};
export default App;
1
Which of the following code snippets will print 'Hello World' to the console?1
I can launch the debugger in Chrome from my app, I run `react-native log-ios` from my command line1
How to use StyleSheet in React Native