Complete the code to create a simple React Native component that displays "Hello World".
import React from 'react'; import { Text, View } from 'react-native'; export default function App() { return ( <View> <[1]>Hello World</[1]> </View> ); }
The Text component is used to display text in React Native.
Complete the code to add a button that shows an alert when pressed in React Native.
import React from 'react'; import { Button, Alert, View } from 'react-native'; export default function App() { return ( <View> <Button title="Press me" onPress={() => [1]('Button pressed!')} /> </View> ); }
alert which works in web but not recommended in React Native.console.log which only logs to console.Alert.alert is the correct way to show an alert dialog in React Native.
Fix the error in the React Native style object to center content vertically and horizontally.
const styles = {
container: {
flex: 1,
justifyContent: '[1]',
alignItems: 'center',
},
};justifyContent: 'center' centers content vertically in a flex container.
Fill both blanks to create a Flutter widget that shows a centered text.
import 'package:flutter/material.dart'; class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( home: Scaffold( body: [1]( child: [2]('Hello Flutter!'), ), ), ); } }
Container instead of Center for centering.Column which arranges children vertically but does not center by default.Center widget centers its child, and Text displays text in Flutter.
Fill all three blanks to create a React Native StyleSheet with a red background and white centered text.
import { StyleSheet } from 'react-native'; const styles = StyleSheet.create({ container: { backgroundColor: '[1]', flex: 1, justifyContent: '[2]', alignItems: '[3]', }, text: { color: 'white', }, });
The container background should be 'red'. Both justifyContent and alignItems set to 'center' center content vertically and horizontally.