React native
thinkwik

React native

React native basic

Learn the Basics

React Native is like React, but it uses native components instead of web components as building blocks. So to understand the basic structure of a React Native app, you need to understand some of the basic React concepts, like JSX, components, state, and props. If you already know React, you still need to learn some React-Native-specific stuff, like the native components. This tutorial is aimed at all audiences, whether you have React experience or not.

Let's do this thing.

No alt text provided for this image

Hello World#

In accordance with the ancient traditions of our people, we must first build an app that does nothing except say "Hello, world!". Here it is:

import React from 'react';

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

const HelloWorldApp = () => {

 return (

  <View style={{

    flex: 1,

    justifyContent: "center",

    alignItems: "center"   }}>

   <Text>Hello, world!</Text>

  </View>

 )

}

export default HelloWorldApp;

what's going on here?

1.First of all, we need to import React to be able to use JSX, which will then be transformed to the native components of each platform.

2.On line 2, we import the Text and View components from react-native

Then we find the HelloWorldApp function, which is a functional component and behaves in the same way as in React for the web. This function returns a View component with some styles and aText as its child.


The Text component allows us to render a text, while the View component renders a container. This container has several styles applied, let's analyze what each one is doing.


The first style that we find is flex: 1, the flex prop will define how your items are going to "fill" over the available space along your main axis. Since we only have one container, it will take all the available space of the parent component. In this case, it is the only component, so it will take all the available screen space.

The following style is justifyContent: "center". This aligns children of a container in the center of the container's main axis and finally we have alignItems: "center", which align children of a container in the center of the container's cross axis.

Some of the things in here might not look like JavaScript to you. Don't panic. This is the future.

First of all, ES2015 (also known as ES6) is a set of improvements to JavaScript that is now part of the official standard, but not yet supported by all browsers, so often it isn't used yet in web development. React Native ships with ES2015 support, so you can use this stuff without worrying about compatibility. import, export, const and from in the example above are all ES2015 features. If you aren't familiar with ES2015, you can probably pick it up by reading through sample code like this tutorial has. If you want, this page has a good overview of ES2015 features.

The other unusual thing in this code example is <View><Text>Hello world!</Text></View>. This is JSX - a syntax for embedding XML within JavaScript. Many frameworks use a specialized templating language which lets you embed code inside markup language. In React, this is reversed. JSX lets you write your markup language inside code. It looks like HTML on the web, except instead of web things like <div> or <span>, you use React components. In this case, <Text> is a Core Component that displays some text and View is like the <div> or <span>

.Read on to find out more about the digital marketing world!

www.innerworkindia.com

hashtag

#reactnative hashtag

#marketing hashtag

#crossplatform

#helloworld hashtag

#socialmedia hashtag

#media hashtag

#android hashtag

#ios hashtag

#commerce hashtag

#contentmarketing hashtag

#mobilemarketing hashtag

#socialmediamarketing hashtag

#google






要查看或添加评论,请登录

社区洞察

其他会员也浏览了