React tutorial for beginners ⚛️

Bro Code
9 Oct 202320:27

Summary

TLDRThis video tutorial offers an introduction to ReactJS, a popular JavaScript library for building user interfaces. It explains that React uses components, similar to Lego blocks, to construct web applications. The video covers the basics of JSX, a syntax extension that allows HTML-like code within JavaScript files, and the concept of the virtual DOM for efficient rendering. The tutorial guides viewers through installing Node.js, setting up a React project, and creating simple components like Header, Footer, and a Food list. It also touches on project structure, including the roles of 'node_modules', 'public', and 'src' folders, and demonstrates how to use and reuse components within a React application.

Takeaways

  • 😀 React is a JavaScript library for building user interfaces, not a framework.
  • 🔧 Components in React are reusable sections of code, akin to Legos, that can be assembled to form complex web applications.
  • 📝 JSX, or JavaScript XML, is a syntax extension that allows writing HTML-like code within JavaScript files.
  • 🌐 The Virtual DOM in React is a lightweight representation of the real DOM, enabling efficient updates by only applying changes to the real DOM when necessary.
  • 🛠️ Prerequisites for starting with React include knowledge of JavaScript, HTML, and CSS, as well as familiarity with ES6 features like arrow functions.
  • 💻 Node.js is required for React development, providing a backend JavaScript runtime environment and the Node Package Manager (npm).
  • 📂 The project structure of a React application includes folders like 'node_modules' for external libraries, 'public' for public assets, and 'src' for source code.
  • 🔄 To create a new React project, use the `npm create vite@latest` command, which sets up a development environment with a modern toolchain.
  • 🔗 Components are imported and used within other components by referencing them within the return statement, allowing for a modular and maintainable codebase.
  • ⚙️ React components can contain both JavaScript logic and HTML structure, and can be styled with CSS, either through dedicated stylesheets or inline styles.

Q & A

  • What is ReactJS?

    -ReactJS is a JavaScript library used to build and arrange user interfaces for web applications. It focuses on creating web applications using components, which are reusable building blocks of code.

  • What is a component in React?

    -A component in React is a self-contained section of code that functions as a reusable building block, similar to Legos, where each Lego represents a section of reusable JavaScript and HTML code.

  • What is JSX and how is it used in React?

    -JSX is a syntax extension of JavaScript known as JavaScript XML. It allows you to write HTML-like code within your JavaScript files, making it easier to integrate HTML with React components.

  • What is the Virtual DOM and why is it used in React?

    -The Virtual DOM is a lightweight version of the real DOM of a web page. It helps keep track of changes made to it, and only applies those specific changes to the real DOM without needing to refresh the entire web page, reducing rendering performance overhead.

  • What are the prerequisites for learning React?

    -To learn React, you should know JavaScript, including arrays, classes, objects, and ES6 features like arrow functions. HTML is also mandatory since React components involve rendering HTML elements.

  • How do you install Node.js and why is it necessary for React?

    -Node.js can be downloaded from nodejs.org. It is necessary for React because it provides a backend JavaScript runtime environment and includes the Node Package Manager (npm), which is used to manage packages and dependencies for React projects.

  • What is a text editor and why is it needed for React development?

    -A text editor is a program used for editing plain text files. For React development, a text editor like Visual Studio Code (VS Code) is recommended as it provides features that aid in coding, such as syntax highlighting and debugging tools.

  • How do you create a new React project using npm?

    -To create a new React project, you use the command `npm create vite@latest` in the terminal or command prompt within your project folder. This command sets up a new React project with a development server.

  • What is the purpose of the 'node_modules' folder in a React project?

    -The 'node_modules' folder contains external libraries and packages that the React project relies on, including build tools, utility libraries, and routing libraries.

  • What is the role of the 'public' folder in a React application?

    -The 'public' folder in a React application contains public assets such as fonts, images, and videos that are not bundled during the final output and are typically available via a URL.

  • How do you create a new component in React?

    -To create a new component in React, you create a new .jsx file, define a function with the name of the component, and export it using `export default`. Within this function, you can return a combination of JavaScript and HTML to define the component's structure.

Outlines

00:00

🚀 Introduction to ReactJS

The video introduces ReactJS as a JavaScript library for building user interfaces, emphasizing its component-based architecture. Components are likened to Legos, reusable sections of code that can be assembled into complex structures. React uses JSX, an extension of JavaScript that allows HTML-like code to be written within JavaScript files. It also employs a virtual DOM for efficient rendering updates. The video outlines the prerequisites, including knowledge of JavaScript, HTML, and CSS, and provides a brief overview of the installation process for Node.js and setting up a React project using the 'npm create vite@latest' command.

05:01

🛠 Setting Up the React Environment

The tutorial continues with instructions for setting up the React development environment. It details the installation of Node.js, the use of a text editor like VS Code, and the creation of a project folder. The video demonstrates how to initiate a new React project using the terminal and npm, and how to start the development server. It also explains the project structure, including the roles of the 'node_modules', 'public', and 'src' folders, and the importance of files like 'index.html' and 'package.json'.

10:04

🏗 Building React Components

The presenter guides viewers through creating and structuring React components. It covers the creation of a 'Header' component, explaining how to write a function-based component, export it for use elsewhere, and return a combination of JavaScript and HTML. The video also shows how to import and use this component within the 'App' component. It further demonstrates adding elements like navigation links and a horizontal rule to the 'Header' component, and how to style them using CSS.

15:07

🔗 Component Reusability and Dynamic Content

This section delves into the reusability of React components, showing how to create a 'Footer' component and dynamically insert the current year using JavaScript. It also covers creating a 'Food' component, demonstrating the use of variables and methods within the return statement to display a list of foods. The video highlights the flexibility of component arrangement and the ability to reuse components in various configurations to alter the layout and style of the web application.

20:07

🌟 Wrapping Up the React Introduction

The video concludes with a summary of the key concepts introduced, emphasizing the importance of component-based development in React. It reiterates that components are small, reusable pieces of code that can include both JavaScript and HTML, and that functions return this code to make it reusable. The tutorial serves as a foundational introduction to React, setting the stage for more advanced topics and component usage.

Mindmap

Keywords

💡ReactJS

ReactJS is a JavaScript library for building user interfaces, particularly for single-page applications. It allows developers to create reusable UI components. In the video, ReactJS is introduced as the main topic, and the script discusses its features and how to get started with it.

💡Components

In ReactJS, a component is a self-contained section of code that represents a reusable building block. Components can be thought of as the Lego blocks of React, where each block is a piece of UI that can be used to build a larger application. The script uses the analogy of Legos to explain how components can be combined to create complex web applications.

💡JSX

JSX, or JavaScript XML, is a syntax extension for JavaScript that allows HTML-like code to be written within JavaScript files. This enables developers to mix HTML with JavaScript, making it easier to create React components. The script mentions JSX as a key feature of React, allowing for the creation of components that include both HTML and JavaScript.

💡Virtual DOM

The Virtual DOM is a programming concept where an in-memory representation of the DOM is kept and synced with the real DOM. React uses the Virtual DOM to optimize performance by only updating the parts of the web page that have changed, rather than refreshing the entire page. The script explains how React utilizes the Virtual DOM to enhance rendering performance.

💡Node.js

Node.js is a JavaScript runtime that allows JavaScript to be run on the server-side, outside of the browser. In the context of the video, Node.js is necessary for setting up the development environment for React applications. The script includes instructions on how to download and install Node.js.

💡npm

npm stands for Node Package Manager, which is a tool that comes with Node.js. It is used to manage packages and dependencies for JavaScript projects. The script provides instructions on using npm to create a new React project and to start the development server.

💡Vite

Vite is a build tool that simplifies the process of setting up a modern web development environment. It is used as an alternative to 'create-react-app' and is mentioned in the script as a tool for creating a new React project quickly and efficiently.

💡ES6

ES6, or ECMAScript 2015, is a version of the JavaScript language that introduced several new features, including arrow functions, classes, and modules. The script mentions that knowledge of ES6 features is necessary for working with React, as these features are commonly used in React components.

💡CSS

Cascading Style Sheets (CSS) is used for styling web pages. In the video, CSS is mentioned as a mandatory skill for working with React, as React components often involve rendering HTML elements with applied styles. The script also discusses how CSS can be applied to React components.

💡Project Structure

The project structure refers to the organization of files and folders in a software project. The script provides an overview of the typical structure of a React project, including the 'node_modules' folder, 'public' folder, 'src' folder, and 'package.json' file, explaining the purpose of each component of the structure.

💡Component Reusability

Component reusability is a core concept in React where components are designed to be used multiple times throughout an application. The script demonstrates how to create a reusable component and how it can be included in different parts of the application to build the UI.

Highlights

React is a JavaScript library for building user interfaces, not a framework.

React focuses on components, which are reusable building blocks of code.

Components are analogous to Legos, representing sections of reusable JavaScript and HTML code.

JSX (JavaScript XML) allows writing HTML-like code within JavaScript files.

React utilizes a virtual DOM for efficient tracking and updating of changes in the web page.

Knowledge of JavaScript, including ES6 features like arrow functions, is necessary for using React.

HTML is mandatory for rendering HTML elements in React components.

Node.js is required for React development, providing a backend JavaScript runtime environment.

VS Code is recommended as the text editor for React development.

The project folder is created on the desktop for convenience.

NPM (Node Package Manager) is used for managing project dependencies.

Create React App is used for setting up the React development environment.

The project structure includes node_modules, public, and source folders.

The public folder contains public assets like images and fonts that are not bundled.

The source folder is where most development work occurs, including creating React components.

Components can have dedicated stylesheets for styling.

The main entry point of a React application is the index.html file.

Components are created as functions that return JSX elements.

Components can be imported and used within other components to build the UI.

JSX elements must be wrapped in an enclosing tag, such as a fragment, when returning multiple components.

React components can include both JavaScript and HTML, making them highly reusable.

The project structure and component reusability are key features of React for efficient web development.

Transcripts

play00:00

hey what's going on everybody it's your

play00:01

bro hope you're doing well and in

play00:03

today's video I'm going to show you

play00:04

everything you need to know to get

play00:05

started working with reactjs so why

play00:08

don't you go ahead and sit back relax

play00:10

and enjoy the

play00:12

show react is a JavaScript library not

play00:16

framework that's used to easily build

play00:18

and arrange user interfaces for web

play00:21

applications react focuses on building a

play00:23

web application using these things

play00:25

called components a component is a

play00:27

self-contained section of code that

play00:29

functions as as a reusable building

play00:31

block think of Legos you could say a

play00:32

Lego is similar to react component each

play00:35

Lego represents a section of reusable

play00:37

JavaScript and HTML code we can build a

play00:39

diarama or other complicated structure

play00:42

from these Legos if we use enough of

play00:44

them and in the correct places react

play00:46

uses a syntax extension of JavaScript

play00:48

known as jsx meaning JavaScript XML jsx

play00:52

allows you to write HTML like code

play00:55

within your JavaScript files react also

play00:57

utilizes a virtual Dom it's a

play00:59

lightweight version of the real Dom of a

play01:01

web page we can keep track of any

play01:03

changes made to the virtual Dom and only

play01:05

apply that specific change to the real

play01:07

Dom without needing to refresh the

play01:09

entire web page only that specific

play01:11

section this reduces rendering

play01:13

performance overhead before we do begin

play01:15

you will need to know JavaScript since

play01:17

react is a JavaScript library everything

play01:19

up to arrays classes objects and es6

play01:22

feature such as Arrow functions will be

play01:24

necessary HTML will also be mandatory

play01:27

since our react components involve

play01:29

rendering HTML elements and applying CSS

play01:32

I do have full free courses on my

play01:33

YouTube channel on these topics if you

play01:35

need to catch up or you need a refresher

play01:37

so that's a quick overview of react

play01:38

we'll move on to the installation

play01:40

instructions next we're going to

play01:42

download nodejs from this URL nodejs.org

play01:46

node.js is a backend JavaScript runtime

play01:49

environment it executes JavaScript code

play01:51

outside of a web browser we're mostly

play01:53

interested in the node package manager

play01:55

that comes with it let's download the

play01:58

latest version of node.js

play02:01

open it when the download is

play02:06

complete select next read the license

play02:09

agreement yes I did read it that fast

play02:12

next select a destination folder I'll

play02:15

keep it as

play02:16

is you can define a custom setup but

play02:19

that's outside of the scope of this

play02:21

tutorial series we'll press next we'll

play02:24

skip tools for Native modules press next

play02:28

and

play02:28

install

play02:32

then

play02:33

finish you'll also need a text editor I

play02:36

recommend vs code since you've made it

play02:39

this far in my web development series

play02:41

I'm assuming you already have one

play02:42

downloaded which you can get from this

play02:44

site code dovisual studio.com and select

play02:46

the correct download for your operating

play02:48

system within VSS code I'm going to

play02:51

create a project folder let's go to

play02:53

explore open folder just for convenience

play02:57

I'll place my project folder on my

play02:59

desktop

play03:00

I'll create a new folder I'll name mine

play03:04

website then we will select this

play03:07

folder we're going to need to open up

play03:09

command prompt if you're using Windows

play03:11

or terminal if you're on Mac you can

play03:13

also do this within vs code go to the

play03:15

hamburger menu up top terminal new

play03:21

terminal we within our website folder we

play03:24

will type the command npm meaning node

play03:27

package

play03:28

manager

play03:30

create vit at latest meaning latest

play03:34

version V's a development server it's a

play03:38

modern replacement to create react app

play03:40

which is now

play03:42

outdated hit

play03:44

enter we'll need a name for this project

play03:47

a common naming convention for a user's

play03:49

first react project is my react app

play03:54

that's a common name that you'll see

play03:56

enter select a framework using the arrow

play03:59

keys we can select whatever framework we

play04:01

would like to use we will select react

play04:04

hit enter are we going to use typescript

play04:07

or JavaScript we'll stick with plain

play04:10

JavaScript all right here are the last

play04:12

few commands and they are given to us

play04:15

we'll change the directory to our react

play04:18

app CD meaning change directory my react

play04:23

app and that's the name of the folder

play04:25

where our project is

play04:27

located npm install that is the second

play04:35

command the last command is npm runev to

play04:39

start the development server npm

play04:43

runev all right so our web server is

play04:45

found at this address let's copy it then

play04:48

open up a web browser let's paste that

play04:51

address and here we are within our

play04:53

development server this is a sample

play04:56

project that's given to us it even

play04:58

includes this little counter

play05:01

hey this is future bro I was editing

play05:03

this video and I totally forgot to

play05:05

mention how you can restart the server

play05:07

if you close out of it all you got to do

play05:09

is open up a terminal let's go to

play05:10

terminal new terminal we have to be sure

play05:13

that we're within our application folder

play05:15

I'm going to change my directory by

play05:17

typing CD the name of the folder my

play05:21

react

play05:23

app then npm run Dev to start the

play05:27

development

play05:28

server

play05:30

and let's refresh that yep it seems like

play05:33

it's working so yes I forgot to mention

play05:35

that that is all I'm quickly going to

play05:37

cover the project structure of our react

play05:39

application we'll begin with the node

play05:41

modules folder this folder contains

play05:44

external libraries and packages that our

play05:46

project relies on a few of which are

play05:49

build tools utility libraries routing

play05:51

libraries just to name a few we won't be

play05:55

spending any time directly in this

play05:56

folder but you should still be aware

play05:58

what it's for if it just contains

play06:00

external libraries and packages that our

play06:02

project relies on next we have the

play06:04

public folder the public folder contains

play06:07

any public assets one of which in here

play06:10

is a vit image it should be this image

play06:12

right here this folder can contain

play06:15

public fonts images videos they're not

play06:18

bundled during the final output they're

play06:20

typically available via a URL just to

play06:23

demonstrate I'm going to delete this

play06:25

image file and see what

play06:27

happens yep and that logo is gone so my

play06:31

v logo was a public asset via a URL and

play06:35

let's put that

play06:36

back then we have the source folder

play06:39

we'll spend 99% of our time within the

play06:42

source folder we have an assets folder

play06:44

that can contain images and videos the

play06:47

assets folder is very similar to the

play06:49

public folder but files within the

play06:51

assets folder are bundled during the

play06:53

final output public assets are not and

play06:55

they're generally available via a URL my

play06:59

re act image is within the assets folder

play07:02

currently we have a main jsx file

play07:05

remember that jsx is Javascript XML in a

play07:08

way this functions as our main

play07:10

Javascript file react works with

play07:13

components we're adding a single

play07:14

component an app component which we are

play07:18

importing so let's take a look at our

play07:20

app component the app component in this

play07:23

example you could say is the root

play07:24

component we have two different

play07:26

stylesheets a stylesheet for app and we

play07:30

have an index CSS stylesheet this is the

play07:32

main CSS file for our application we're

play07:35

importing this file from our main jsx

play07:38

file right here so that's the source

play07:40

folder then we have an index HTML file

play07:43

this is the main entry point into our

play07:45

program within the body of our document

play07:48

we have a development with an ID of root

play07:51

as well as a script to our main jsx file

play07:54

a few other things you should know about

play07:56

is this package Json file Json file

play07:59

files are structured in key value pairs

play08:01

this file contains metadata about our

play08:03

project such as the project name the

play08:06

version number what build we're using

play08:08

we're using vit and the react version

play08:11

number just to name a few all right

play08:14

everybody so in just a moment we will be

play08:15

creating our first react component we

play08:18

already do have one component that is

play08:20

app right now this is serving as a

play08:22

sample project for us then we are

play08:24

importing app to main jsx this is our

play08:28

main J s x file think of it as the main

play08:30

JavaScript file we are creating a root

play08:33

element and including our app component

play08:37

within our app component we do have a

play08:39

function delete everything within this

play08:45

function that should eliminate our

play08:47

sample

play08:49

project and we no longer need these

play08:52

Imports we can delete them

play08:54

too but you do want to keep this export

play08:57

statement components can have dedicated

play08:59

stylesheets which you can see here for

play09:01

app CSS we are going to delete this

play09:04

because we no longer need

play09:06

it we do have an app component that's

play09:08

going to serve as the root we will add

play09:10

other components to our app component

play09:12

our app component ties them all together

play09:15

to create a new component go to your

play09:16

Source folder we're going to rightclick

play09:18

then go to new file we will create a

play09:21

component for a header the extension is

play09:25

jsx because it's a JavaScript XML file

play09:30

we will be working with function based

play09:33

components we will create a function

play09:36

with the name of header do pay attention

play09:39

to the

play09:40

capitalization then we would like to

play09:42

export this component so we can import

play09:44

it elsewhere at the end of this file

play09:47

type

play09:48

export default the name of the

play09:52

component header within our header

play09:55

function we can write a combination of

play09:57

JavaScript and HTML

play09:59

all we're going to do within this

play10:00

function is return something return

play10:04

parentheses semicolon within the return

play10:07

statement you can write pure HTML I will

play10:10

create a header

play10:11

element so react components they're only

play10:14

capable of returning a single element

play10:17

but you can place children elements

play10:19

within within our header element I will

play10:21

create an H1 element with text of my

play10:27

website just to be sure everything is

play10:29

working let's save I'm holding contrl s

play10:32

on Windows we will go to our app

play10:34

component then import the header

play10:36

component So within app we will type the

play10:40

statement import the name of the

play10:43

component

play10:45

header from a location that location is

play10:49

going to be do SL header.

play10:54

jsx we can now use this header component

play10:57

within our app component we will also be

play10:59

returning something so we will need a

play11:02

return statement return parentheses

play11:04

semicolon what are we going to return I

play11:08

would like to use my header component so

play11:10

to add a component we need a set of

play11:13

angle brackets then type the name of the

play11:15

component

play11:18

header like this they're a pair of two

play11:22

and the second one is closed that's why

play11:24

we have a forward slash preceding it we

play11:26

now have a header component you can

play11:29

shorten the syntax as well take your

play11:32

component end it with the forward slash

play11:35

that also works too it's a shorthand way

play11:37

of writing the same thing let's head

play11:39

back to our header component We'll add a

play11:41

few more

play11:42

elements after our H1 element let's

play11:45

create a navigation

play11:47

element then within the navigation

play11:49

element we'll create an unordered

play11:52

list within the unordered list we'll

play11:54

create a few list

play11:57

items the first will be

play12:01

home these are list items you would

play12:03

typically see for a navigation bar

play12:07

home

play12:11

about

play12:15

services and

play12:17

contact we now have our unordered list

play12:21

I'll enclose our list items within

play12:23

anchor tags to make them

play12:25

hyperlinks a hre equals

play12:29

I don't want these to go anywhere I'm

play12:30

just going to leave these empty I'll add

play12:33

a pound

play12:34

sign and then be sure to close these

play12:37

anchor

play12:38

tags we'll place our text within the

play12:40

anchor tag so they are now hyperlinks

play12:43

okay let's do that for the other list

play12:53

items there we are then after my

play12:56

navigation element I will add a

play12:58

horizontal rule to make it look

play13:00

nice okay there is our header component

play13:04

we no longer need to work with this

play13:05

header component we do have some styling

play13:08

already applied those Styles can be

play13:09

found within index.css if you would like

play13:13

to start fresh and eliminate all of

play13:14

these Styles you can delete everything

play13:16

from here then you do have HTML with no

play13:20

CSS in a future video I'll show you

play13:22

various ways in which we can apply CSS

play13:24

to a react component but for now we'll

play13:26

just keep this the same our head element

play13:29

is now complete we will create a new

play13:31

element for a footer again go to our

play13:34

source folder right click go to new

play13:37

file

play13:38

footer.

play13:41

jsx we are creating a function based

play13:44

component it's a function that's going

play13:47

to return a footer

play13:50

component then at the end of our script

play13:53

we will export default the name of the

play13:56

component footer so that we we can

play13:58

import it elsewhere our footer is going

play14:01

to return something so we need a return

play14:04

statement then within the set of

play14:06

parentheses we can return a single

play14:08

element we will return a footer

play14:13

element but remember you can place

play14:15

children elements within an element it

play14:17

still only counts as one then so what do

play14:20

we want to do for our

play14:21

footer I'll include a paragraph

play14:27

element

play14:29

within the paragraph element I'm going

play14:30

to add a copyright symbol to add a

play14:32

copyright Mark Type ampersand copy semi

play14:36

call

play14:37

in then afterwards I'll add your website

play14:43

name all right now we need to import

play14:46

this footer going back to our app

play14:49

component we will

play14:51

import

play14:53

footer from footer.

play14:57

jsx then I would like to include a

play15:00

footer component after the

play15:03

header now pay attention to

play15:06

this we're returning two

play15:09

components we have this warning we only

play15:12

have the capability of returning a

play15:14

single component that's how our return

play15:16

statements are designed jsx elements

play15:18

must be wrapped in an enclosing tag do

play15:21

you want a jsx fragment so since we only

play15:25

have the capability of returning a

play15:26

single enclosing tag we're we're going

play15:28

to enclose our components with what's

play15:30

known as a

play15:32

fragment it's just an empty set of anle

play15:35

brackets so we will enclose all

play15:37

components within a

play15:40

fragment and that should work we have

play15:42

our footer component following our

play15:44

header component we have our

play15:47

header and our footer let's make a few

play15:50

more changes to our

play15:52

footer I'm going to zoom out a little

play15:55

bit within our return statement we can

play15:57

insert some Javas script to insert some

play16:00

JavaScript you need a set of curly

play16:02

braces I will create a new date object

play16:06

this is some JavaScript code

play16:09

new date parentheses I would just like

play16:13

the year I will follow this object with

play16:16

get full year method let's save and take

play16:20

a look so I'm filming this video near

play16:23

the end of 2023 your web application

play16:26

should return the current year when ever

play16:28

you're watching this all right our

play16:30

footer component is now

play16:32

done I'm going to create a component for

play16:35

a unordered list to sandwich between our

play16:37

header and our footer I'll create a

play16:40

component for food we will go to our

play16:42

source folder create a new file this

play16:46

component will be food.

play16:50

jsx again we are creating a function

play16:53

based component with the name of

play16:57

food then we will export this component

play16:59

when we're done export default

play17:03

food be sure to add a return

play17:07

statement before we add anything to the

play17:09

return statement I will create some

play17:11

JavaScript variables so normally if

play17:14

you're adding JavaScript code within the

play17:16

return statement you need a set of curly

play17:18

braces but outside of the return

play17:20

statement you don't I will create two

play17:23

JavaScript constants const food one pick

play17:28

some food for me I will pick an

play17:31

orange let's make that

play17:34

Capital all right then let's create a

play17:36

second food

play17:38

variable food 2 for me will be a

play17:42

banana within the return statement we

play17:44

can utilize these

play17:46

constants what do we want to return

play17:49

exactly I will return an unordered

play17:54

list we'll have a few list

play17:57

items three to be

play18:00

exact my first list item I'll just add

play18:03

some text I'll add an

play18:05

apple just to be sure that everything is

play18:08

working let's import this food component

play18:10

from our app

play18:12

component again we need an import

play18:14

statement import food from food. jsx we

play18:20

can now use the food component we will

play18:23

add that after the header we will add

play18:27

food then here is our first list item an

play18:30

apple okay let's head back to our food

play18:33

component for our second list item I

play18:35

will add food one that's our constant

play18:38

now pay attention to this if I type food

play18:40

one well we're literally printing the

play18:43

text food one since we're within our

play18:45

return statement I would like to include

play18:47

some JavaScript code we're including a

play18:49

JavaScript variable so I need to enclose

play18:53

this variable within a set of curly

play18:55

braces because we're within the return

play18:57

statement and now now my second list

play18:59

item is an orange then let's include

play19:02

food 2 but I'm going to add one more

play19:04

thing food 2 however I'm going to use

play19:08

the builtin 2 uppercase method just to

play19:12

demonstrate that we can use JavaScript

play19:14

functions all right and there is our

play19:16

unordered list we have an apple orange

play19:18

and a

play19:19

banana so these components are now

play19:21

complete and the cool thing about react

play19:23

as well is that we can keep on reusing

play19:25

these components if we would like I

play19:27

would like a couple food components so I

play19:29

will just paste another component we now

play19:31

have two food components or even three

play19:34

or

play19:35

four you can rearrange these components

play19:38

however you would like by rearranging

play19:40

them we can change the feel and style of

play19:42

our web application for demonstration

play19:44

purposes I will put our footer on the

play19:46

top that doesn't make any sense but I

play19:48

just want to demonstrate so our footer

play19:51

is now on the top followed by the header

play19:53

then the food component or maybe I would

play19:56

like the food component on top

play20:00

we now have our food component footer

play20:02

component then our header

play20:06

component all right everybody that is an

play20:08

introduction to react react is all about

play20:11

reusing components a component is a

play20:14

small section of code that can include

play20:16

JavaScript and HTML your function will

play20:19

return that code and make it reusable

play20:21

and that is your introduction to

play20:25

react

Rate This

5.0 / 5 (0 votes)

Related Tags
ReactJSWeb DevelopmentComponentsJSXTutorialJavaScriptUI BuildingCodingDevelopmentTech