Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> JavaScript

React Native में Hello World प्रदर्शित करने का प्रोग्राम लिखें


एक बार जब आपके सिस्टम पर React Native इंस्टॉल हो जाता है, तो आपको App.js में डिफ़ॉल्ट कोड मिलना चाहिए जैसा कि नीचे दिखाया गया है:

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
export default class App extends React.Component {
    render() {
        return (
            
                Open up App.js to start working on your app!
                Changes you make will automatically reload.
                Shake your phone to open the developer menu.
            
        );
    }
}
const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
    },
});

अब आप अपनी आवश्यकता के अनुसार कोड बदलने के लिए स्वतंत्र हैं। हम यहां ऐप में Hello World टेक्स्ट प्रदर्शित करने में रुचि रखते हैं।

शुरू करने के लिए आपको पहले आवश्यक कंपोनेंट्स और मॉड्यूल्स इम्पोर्ट करने होंगे। हमें React मॉड्यूल की आवश्यकता है तो आइए पहले उसे इम्पोर्ट करें जैसा कि नीचे दिखाया गया है:

import React from 'react';

अब आइए उन अन्य कंपोनेंट्स को इम्पोर्ट करें जिनका उपयोग हम Hello World टेक्स्ट प्रदर्शित करने के लिए अपने कोड में करने जा रहे हैं।

import { StyleSheet, Text, View } from 'react-native';

हमने StyleSheet, Text और View कंपोनेंट इम्पोर्ट किए हैं। हमें View और Text कंपोनेंट को स्टाइल करने के लिए StyleSheet कंपोनेंट की आवश्यकता है। View कंपोनेंट पैरेंट कंपोनेंट होगा जिसके चाइल्ड के रूप में Text कंपोनेंट होगा।

App डिफ़ॉल्ट क्लास है जिसे एक्सपोर्ट किया जाता है और जब आप प्रोजेक्ट चलाते हैं तो आपको अपने डिवाइस पर <Text> कंपोनेंट में टेक्स्ट देखना चाहिए जैसा कि नीचे दिखाया गया है:

export default class App extends React.Component {
    render() {
        return (
            
                Open up App.js to start working on your app!
                Changes you make will automatically reload.
                Shake your phone to open the developer menu.
            
        );
    }
}

टेक्स्ट को Hello World में बदलें जैसा कि नीचे दिखाया गया है:

export default class App extends React.Component {
    render() {
        return (
            
                Hello World
            
        );
    }
}

स्टाइल के प्रॉप्स View कंपोनेंट में जोड़े जाते हैं। दिया गया मान styles.container है। प्रॉप्स मान को कर्ली ब्रैकेट्स {} में दिया जाना होता है यानी style={styles.container}।

styles ऑब्जेक्ट StyleSheet.create() का उपयोग करके बनाया जाता है। आपके सभी कंपोनेंट्स के लिए स्टाइल StyleSheet.create() के अंदर परिभाषित किए जा सकते हैं। अभी हमने कंटेनर स्टाइल परिभाषित किया है जिसका उपयोग View कंपोनेंट पर <View style={styles.container}></View> के रूप में किया जाता है। forText वेरिएबल की स्टाइल का उपयोग Text कंपोनेंट को स्टाइल करने के लिए किया जाता है।

const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
    },
    forText: {
        color: 'green',
        fontSize: '25px'
    }
});

यहां पूरा कोड दिया गया है जो React Native का उपयोग करके आपकी मोबाइल स्क्रीन पर Hello World प्रदर्शित करने में मदद करता है।

import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
export default class App extends React.Component {
    render() {
        return (
            Hello World
        );
    }
}
const styles = StyleSheet.create({
    container: {
        flex: 1,
        backgroundColor: '#fff',
        alignItems: 'center',
        justifyContent: 'center',
    },
    forText: {
        color: 'green',
        fontSize: '25px'
    }
});

आउटपुट

React Native में Hello World प्रदर्शित करने का प्रोग्राम लिखें


  1. React Native में Material Chip View कैसे प्रदर्शित करें React Native में Material Chip View कैसे प्रदर्शित करें

    UI में चिप्स प्रदर्शित करने के लिए हम React Native Paper Material Design का उपयोग करने जा रहे हैं। React Native Paper को नीचे दिखाए अनुसार इंस्टॉल करें: npm install --save-dev react-native-paper चिप कंपोनेंट UI पर इस प्रकार दिखता है: बेसिक चिप कंपोनेंट इस प्रकार है: <Chip icon=icontodisplay onP

  1. C प्रोग्राम: सरणी को उलटें (Reverse Array) C प्रोग्राम: सरणी को उलटें (Reverse Array)

    संबंधित आइटम्स का समूह जो एक सामान्य नाम से संग्रहीत होता है, सरणी कहलाता है। सिंटैक्स datatype array_name[size]; आरंभीकरण घोषणा के समय आरंभीकरण: int a[5] = {10, 20, 30, 40, 50}; C में सरणी उलटना हम स्वैपिंग तकनीक का उपयोग करके सरणी को उलट सकते हैं। उदाहरण: यदि P चार एलिमेंट्स की पूर्णांक सरणी ह

  1. C प्रोग्राम: सभी डेटा प्रकारों की रेंज को सारणीबद्ध रूप में प्रदर्शित करना C प्रोग्राम: सभी डेटा प्रकारों की रेंज को सारणीबद्ध रूप में प्रदर्शित करना

    C प्रोग्रामिंग में हमारे द्वारा उपयोग किए जाने वाले विभिन्न डेटा प्रकार पूर्णांक, शॉर्ट इंट, साइन्ड और अनसाइन्ड चार आदि हैं। डेटा प्रकार डेटा प्रकार मानों के सेट और डेटा के प्रकार को निर्दिष्ट करता है जिसे एक वेरिएबल में संग्रहीत किया जा सकता है। वे प्रोग्रामर को एप्लिकेशन की आवश्यकताओं के लिए उपयु