Intro to basic React Native Components like View and Text.
Tags: react, javascript, beginners, tutorial
Published: 2020-12-03 05:38:38

In this post I will discuss about the basic React Native tags like,

- View 
- Text 
- TextInput  
- StyleSheet to style our react-native components.

This post is a part of my React Native series.

Before we use these above mentioned React Native tags we need to import them first.

```js

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

```

Now lets learn about these tags.

<strong> 1.  View:</strong>

View is just like div in react.js where we use it to wrap the parent components in the return statements.

The comparison can be visualised like below,

```js
// React.js 'div'
return(

<div>
<span>Text</span>
</div>

)

// React Native 'View'
return(

<View>
<Text> Text </Text>
</View>


```
As clearly said in the documentation,

> View is the most fundamental component for building UI in a react native mobile app.

Each and every file in a react native must have <code>View</code> wrapped around it's return statement.

<strong>2. Text: </strong>

<Text> can be used to display text a message or any normal text to the frontend screen in react native.

It's analogous(comparable to) many html elements like

- p tag
- h1- h6 tags
- span, div tags which are used to display text messages.

```js

return(
<View>
<Text> My name is Gautham</Text>
</View>

```

<strong> 3. TextInput: </strong> 

It is used to get the input values from the user in React Native.

The same concept of onChange applies here as well.

```js

import React,{useState} from 'react'

const app = () =>{
const [inputValue,setinputValue] = useState('')
return(
<View>

<TextInput onChange={value =>setinputValue(value)} value={inputValue}> My name is Gautham</TextInput>

</View>
}
```

<strong> 4.  StyleSheet: </strong>

We can add styles in our react native app by using <strong> StyleSheet </strong>.

We create a variable and input all our CSS properties we need here.

It must be made in an object format so that each react native tags can have different styles when we pass the object's keys as props in <code> style={} </code>

The very big advantage for frontend developers who are good at CSS is, there is no need to learn any new properties to style React Native tags and we can use regular CSS properties but the only difference is we must use <strong> camelCase </strong>.

Example, 

- font-size must be used as fontSize.
- background-color --> backgroundColor.

```js

return(

<View>
<Text style = {styles.textstyle}>
</Text>
</View>

)
const styles = StyleSheet.create({
 
  textstyle: {
    color: 'red',
    fontSize : '30px'
  },
});

```
The text message will be displayed in red color with a font-size of 30px.

And these are the basic React Native Tags you need to know as a beginner.

Play around with the styleSheet concepts with your own CSS properties.

You can refer the [react-native docs](https://reactnative.dev/) as it explains these concepts really well and I learnt from it.

In my next post I will be covering some more react native tags like,

- TouchableOpacity
- Button
- Image
- Flatlist and more.

Stay tuned.

### Thank you for reading!!

<strong> <u>Check out my portfolio: </u> [Gautham's portfolio](https://gautham-portfolio.netlify.app/)</strong>

<strong> <u> Check out my blog: </u>[coding-magnified.tech](https://coding-magnified.tech)</strong>

If you want to appreciate my or support me, you can buy me a coffee with the link below,

<a href="https://www.buymeacoffee.com/XJvD4NhAK" target="_blank">
<img width="250px" height="100px"src="https://dev-to-uploads.s3.amazonaws.com/i/xwa28cylrit799s70lrs.png" alt="Buy Me a Coffee"</img>
</a>

### <u>My Other Articles: </u>

- [Universal CSS properties everyone must know](https://dev.to/gautham495/universal-css-properties-everyone-must-use-4kie)

- [Create-react-app](https://dev.to/gautham495/creating-a-new-react-app-with-create-react-app-4e9m)

- [Git for beginners](https://dev.to/gautham495/basic-git-knowledge-for-beginners-m4p)

 
- [Change headers in react with react-helmet](https://dev.to/gautham495/changing-headers-in-react-with-react-helmet-d0d)

- [Know How to apply box-shadow on all four sides.](https://dev.to/gautham495/know-how-to-apply-box-shadow-on-all-four-sides-43pn)
 
- [Simple CSS Selectors](https://dev.to/gautham495/simple-css-selectors-for-beginners-2i44).

- [CSS Pseudo Elements](https://dev.to/gautham495/css-pseudo-elements-for-beginners-53ob).