React Native is built on top of React, a popular JavaScript library for building user interfaces. React Native can be most effectively used by understanding React.
React consists of three core concepts: components, JSX, and the property state. If you want to learn more, see React’s official documentation.
This is your First Component
To illustrate this principle, we will use ‘Pet’ as an example: friendly, approachable animals that need a name and a home. Here’s your first ‘Pet’ component:
import React from ‘react’;
import { Text } from ‘react-native;
const Pet = () => {
return (
<Text>Hello, I am your pet!</Text>
);
}
export default Pet;
Output: Hello, I am your pet!
Using JavaScript’s import function, import the Text Core Component from React and React Native to define your Pet component:
import React from ‘react’;
import { Text } from ‘react-native’;
Initially, your component will be a function:
const Pet = () => {};
Components are like blueprints. The function component’s output is rendered as a React element. Using React elements, you can specify what you want to display on the screen.
In this case, the Pet component will display a <Text> element:
const Pet = () => {
return <Text>Hello, I am your pet!</Text>;
};
JavaScript’s export default allows you to export your function component for use throughout your entire app, like this:
const Pet = () => {
return <Text>Hello, I am your pet!</Text>;
};
export default Pet;
Exporting your component in this way is just one of many options.
Let’s look closely at that return statement. <Text>Hello, I am your pet! is using JSX, a JavaScript syntax that facilitates writing elements.
JSX
React and React Native use an element syntax known as JSX, which lets you write texts within JavaScript like this: <Text>Hello, I’m your pet!</Text>. The JSX syntax allows you to use variables since it is JavaScript. You are declaring a name for the pet, name, and embedding it inside of the curly braces of <Text>.
Curly Braces
Example:
import React from ‘react’;
import { Text } from ‘react-native’;
const Pet = () => {
const name = “Andrew”;
return (
<Text>Hello, I am {name}!</Text>
);
}
export default Pet;
Output: Hello, I am Andrew!
import React from ‘react’;
import { Text } from ‘react-native’;
const getFullName = (firstName, secondName, thirdName) => {
return firstName + ” ” + secondName + ” ” + thirdName;
}
const Pet = () => {
return (
<Text> Hello, I am {getFullName(“Andrew”, “Michel”, “Watson”)} </Text>
);
}
export default Pet;
Output: Hello, I am Andrew Michel Watson!
Curly braces function as a portal to JS functionality in your JSX!
React includes JSX, so if you don’t import React from ‘react’ at the top of your file, it won’t work!
Custom Components
You can nest these components inside each other in React to create new components. Nestable, reusable components are at the heart of the React paradigm.
For example, you can mix Text and TextInput together, and React Native will render them together:
import React from ‘react’;
import { Text, TextInput, View } from ‘react-native’;
const Pet = () => {
return (
<View>
<Text>Hello…</Text>
<TextInput
style={{
height: 40,
borderColor: ‘gray’,
borderWidth: 1
}}
defaultValue=” Hi there!”/>
</View>
);
}
export default Pet;
Output: Hello…
Hi there!
Props
Props, short for “properties,” let you customize React components.
Props can also be used to customize React Native’s Core Components. The following is an example of how you specify the image to be displayed when using Image:
import React from ‘react’;
import { Text, View, Image } from ‘react-native’;
Const PetApp = () => {
return (
<View>
<Image
source={{uri: “https://reactnative.sample/docs/assets/d_pet.png”}}
style={{width: 200, height: 200}}
/>
<Text>Hello, I am your pet!</Text>
</View>
);
}
export default PetApp;
Output: (Image rendered)
Hello, I am your pet!
Props and the Core Components Text, Image, and View allow you to build many things! However, if you want to build something interactive, you’ll need state.
A component should generally be configured through props when it renders. If you expect component data to change over time, keep track of it using state.
React’s use state hook allows you to add state to a component. Hooks let you access the features of React. For instance, useState adds state to functions.
import React, { useState } from “react”;
import { Button, Text, View } from “react-native”;
const Cat = (props) => {
const [isHungry, setIsHungry] = useState(true);
return (
<View>
<Text>
I am {props.name}, and I am {isHungry ? “hungry” : “full”}!
</Text>
<Button
onPress={() => {
setIsHungry(false);
}}
disabled={!isHungry}
title={isHungry ? “Pour me some milk, please!” : “Thank you!”}
/>
</View>
);
}
const Cafe = () => {
return (
<>
<Cat name=”Zeeva” />
<Cat name=”Zoe” />
</>
);
}
export default Cafe;
Output: I am Zeeva, and I am hungry!
POUR ME SOME MILK, PLEASE!
I am Zoe, and I am hungry!
POUR ME SOME MILK, PLEASE!

26 responses to “React Fundamentals”
Yo, I tried plataforma7ff and it’s pretty decent. The thing I liked the most was the mobile experience which was better than other platforms that I’ve used. plataforma7ff
Jeetbaz, never heard o’ it before, but I’m always up for trying something new! Might just be my new favourite. Fingers crossed! jeetbaz
Yo, Betboom9ja is the real deal! Been using it for a minute now and the odds are fire. Definitely worth checking out if you’re looking to spice up your betting game, fam. betboom9ja
a45com https://www.a45com.org
gkbet https://www.gkbeth.org
tayawin https://www.tayawinch.net
peso99 https://www.repeso99.net
taya777login https://www.wtaya777login.com
okebet168 https://www.okebet168u.org
ph789 login https://www.ph789-login.com
philwin https://www.myphilwin.net
Yo, signing up for jalwagames was surprisingly easy. Just a heads-up for anyone looking to jump in and play. Registration’s quick! Join the fun: registerjalwagames
I’ve been poking around on ga888baiser, and it’s got some interesting stuff. If you’re curious, take a peek and see what you think. Could be your new favorite. Check it out: ga888baiser
Just a quick one: 5hbetentrar is pretty easy to navigate. Getting in is smooth. If you’re looking to get started, this is a good spot. Easy access: 5hbetentrar
[5582]VIPPH Online Casino: Top Philippines Slots, Easy Login & App Download Experience VIPPH Online Casino, the #1 hub for Philippines slots. Quick VIPPH login, easy VIPPH register, and fast VIPPH app download. Play VIPPH slots today! visit: vipph
I’ve been using bet10 lately. It’s surprisingly good! Clean interface and fast payouts. Give it a try yourself, bet10.
Heard some stuff about bmw55casino on Bmw55casino.net. Looks like a decent place to try your luck if you’re into that kind of thing. Maybe give it a spin: bmw55casino
Just saw 79kinh on 79kinh.info, if you are interested in this kind of information, might be useful to you. Check this out: 79kinh
[8421]90jili Casino Login | Register Online & Official App Download Join 90jili Casino, the Philippines’ premier destination for online betting. Login or register now to play exciting games and download the official app for seamless access! visit: 90jili
Just stumbled across plataformazww the other day. Its fast site with fun games, i liked it a lot. Check it out here: plataformazww
Just spent an hour on plataforma592bet. It’s another one of these new sites, nothing too special, but runs smoothly and I actually won a bit! Give it a try. Check it out here: plataforma592bet
Just checked out 777milagrocasino. The site design is good, and the games are fun. The customer service was good, too. Check it out here: 777milagrocasino
Если важны качественные ресурсы, подойдут базы форумов для xrumer https://www.olx.ua/d/uk/obyavlenie/progon-hrumerom-dr-50-po-ahrefs-uvelichu-reyting-domena-IDXnHrG.html с высокой репутацией.
Howdy folks, gave vn58ibet a whirl earlier. Seemed alright, decent selection. Check out vn58ibet if you’re hunting for a new bookie.
Downloaded the mnl63 app, and so far, it’s a pretty good mobile experience! Easy access on the go. Test it here: mnl63 app
MNL63 login works perfectly! Logging in was seamless. Hope the wins roll in! Easy access: mnl63 login