React and ReactDOM
by Tomas Trescakยท Setup

Root Folder
Not Attempted
NameProgress
Introduction
Not Read
๐Ÿฐ Player
Not Read
Software Installation
Project Setup
Running and Testing
React and ReactDOM
๐Ÿ’ก Assignment 1: Welcome Message
Not Attempted
Submissions
React
Not Attempted
NameProgress
JSX and Components
Not Read
Props
Not Read
๐Ÿ‘พ Exercise: Props
Not Attempted
CSS Styles
Not Read
useState and Hooks
Not Read
๐Ÿ‘พ Exercise: useState
Not Attempted
Conditional Rendering
Not Read
Lists
Not Read
๐Ÿ‘พ Exercise: Lists
Not Attempted
Forms and Events
Not Read
๐Ÿ‘พ Exercise: Forms
Not Attempted
๐Ÿ’ก Assignment 2: Front End
Not Attempted
Advanced React
Not Attempted
NameProgress
Pure Components - memo
Not Read
Lifecycle - useEffect
Not Read
Expensive? - useMemo
Not Read
DOM Interactions - useRef
Not Read
forwardRef
Not Read
useImperativeHandle
Not Read
๐Ÿ‘พ useImperativeHandle
Not Attempted
Context
Not Read
useCallback
Not Read
useId
Not Read
useReducer
Not Read
Infrastructure
Not Attempted
NameProgress
Database
Not Read
NextAuth and Github Authentication
Not Read
Prisma and ORM
Not Read
Project Setup
Not Read
Project Authentication
Not Read
APIs
Not Attempted
NameProgress
APIs
Not Read
APIs - Slides
Not Attempted
Rest APIs
Not Read
Rest APIs - Express.js
Not Read
ReastAPIs - Next.js
Not Read
Securing APIs
Not Read
Securing APIs - NextAuth
Not Read
tRPC
Not Attempted
NameProgress
tRPC
Not Read
tRPC - Routers
Not Read
tRPC - Server Rendering
Not Read
tRPC - Client Rendering
Not Read
Persisting Data
Not Read
Assignment 3: APIs
Not Read
0 / 250 XP

Lecture Transcript
If you prefer text to video, check out the transcript of the presentation above

If you are looking for a smooth ride in this part of the course, it would be beneficial if you had:

a knowledge of javascript (preferably Typescript). If there are any particularities of Javascript that might seem strange, we will explain them.

a good knowledge of HTML or XML to build the structure of our pages

and an introductory knowledge of CSS to make things look prettier. But do not despair if you are missing one or more prerequisites, we are sure you will be able to tag along! So, all set? Let's get started!

So, what exactly is ReactJS?

React is a JavaScript library created by Facebook, with contributions from worldwide community.

It is designed for building user interfaces

It excels in building complex, interactive, and scalable front-end applications.

Reactโ€™s strength lies in its simplicity and flexibility. It allows developers to compose complex UIs from small, isolated pieces of code called components and reuse those components across multiple projects.

Let me show you an example of what makes React so cool!

Imagine you're building a super cool robot out of LEGOs. Each part of the robot โ€” like its head, arms, and legs โ€” is made from different LEGO blocks.

Now, imagine that you want to build a different robot, but you want to reuse existing body parts, such as feet, head or hips and only modify them a little, such as change their color or adding a small feature.

React works in a similar way!

Imagine you design a really cool component for your website, showing the latest news.

With React, you can easily and efficiently reuse this component across your website, use it on a different website, or even share it with the world by publishing it as an open-source package!

But that's not all! React is also very efficient. For example, when you swap out a hat on your LEGO robot, you do not have to rebuild the entire thing, ReactJS works in a similar way with websites.

Whenever a change needs to happen, like someone clicking a button or typing something, ReactJS updates only the specific parts that need changingโ€”not the entire website. Pretty clever, right?

Let's now honour the tradition and show how to display "Hello World" on your screen using ReactJS. We will also explain the role of the two main packages powering React, the ReactDOM package and the React package.

First, there is the React package, which manages the reactivity of components. You will mainly use this package in your code.

Then, there is the ReactDOM package, which does most of React's background heavy lifting, such as rendering and updating your components into your browser's DOM.

You will usually use the ReactDOM package only once when rendering the root of your React application. This is also our case when rendering the Hello components into a DOM element with the ID "root."

Wow, check out the strange syntax! We are using HTML code inside the javascript code. This syntax is called JSX, and we will dive into it soon.

For now, you can consider that we can define custom HTML elements using Javascript functions, such as our Hello component, which returns the "Hello World" text as an HTML header.

It is time for your first interactive exercise! This time, you can code your exercise directly in piePlayer, or, if you prefer, in the description below.

Your goal is to change the Hello World text to its Spanish equivalent: Hola Mundo! We added unit tests to check your solution, and if you did everything right, your tests will turn green! Make sure to get the correct spelling and punctuation to avoid frustration.

You can browse exercise files in the interactive editor. First, clicking on "Script" allows you to view source code if your solution.

Clicking on CSS will allow you to view and modify styles of your solution. Go ahead and try to make something more funky than this black and white example!

The HTML tab shows the source of the HTML page that we are creating. If you open it, you can see we are loading React and ReactDOM from CDN and adding some fonts. Normally React packages are bundled using a library such as Webpack or SWJS, but that cannot be achieved in the browser.

The test tab shows the source of our unit test file. Please check it out to see what the tests is expecting!

Once you examine all exercise files, it's time to do the work! Currently, the exercise is in the view or read-only mode. You have to press the "Edit" button to launch the editor.

You can modify the code in the editor, most errors are shown immediately as you type.

Once you are done and ready to test your solution, please press the Play button and bask in the glory of green test results!

We will pause the presentation so you can finish the exercise. Once you are ready to continue, please click on the Play button the the piePlayer.

Description
All the extra information about this section

The project you just downloaded uses React, one of the most popular and powerful libraries for building user interfaces in web applications. Created by Facebook, React has transformed the way developers create interactive and dynamic web pages by providing a more efficient method of updating the User Interface (UI).

What is React?

React is a JavaScript library designed to make the process of building complex, interactive UIs more manageable. It excels in handling the view layer for web and mobile apps, allowing developers to create reusable UI components that manage their own state.

Understanding React and ReactDOM

In the React ecosystem, two primary packages play a crucial role:

  1. React: This package contains the core functionality of React, such as defining components, managing component lifecycle, and handling the component state.

  2. ReactDOM: This package provides DOM-specific methods that can be used on the web platform, such as rendering components to the DOM and interacting with the DOM elements. 

Hereโ€™s a simple example of using React and ReactDOM together:


In this code, ReactDOM.render() takes the Hello component and mounts it to the DOM at the specified container, #root. You can find the #root container <div id="root"></div> if you click on the โ€œHTMLโ€ tab in the top menu of the code example. 

๐Ÿ‘พ Exercise 1

Above, is our interactive code editor that allows you to play around with the examples we provide.  We are an international community, please try to change the โ€œHello Worldโ€ message to some other language that you speak. If you speak only English, let's learn how to say โ€œHello Worldโ€ in Spanish: โ€œHola Mundoโ€.

  1. Click on the โ€œEditโ€ button on the top right part of your editor
  2. Click on โ€œScriptโ€ tab in the top menu of the editor
  3. Change the โ€œHello Worldโ€ to your target sentence
  4. Click Play
  5. Observe the magic ๐Ÿช„

React vs. Vanilla JavaScript DOM Manipulations

React differs significantly from vanilla JavaScript (plain JavaScript without libraries or frameworks) when it comes to DOM manipulation. Let's explore these differences through an example:

Vanilla JavaScript:

document.getElementById('app').innerHTML = '<h1>Hello, world!</h1>';

React

function Hello() {
  return <h1>Hello, world!</h1>;
}

ReactDOM.render(<Hello />, document.getElementById('app'));

Key Differences:

  1. Declarative vs. Imperative: React is declarative, which means you tell the program what you want to happen and let React take care of how it happens. Vanilla JavaScript is more imperative, meaning you have to describe step-by-step how things are done.

  2. Efficiency: React minimizes DOM manipulation by using a virtual DOM. When changes are made to the state of an application, React compares the new state with the old state and calculates the minimal set of changes required to update the actual DOM. This leads to a significant performance boost compared to direct DOM manipulation, which is common in vanilla JavaScript.

  3. Reusability: Components in React can be reused across different parts of an application, even with different properties. This modularity is less natural in vanilla JavaScript, where code often becomes repetitive and harder to maintain.

  4. Tooling and Ecosystem: React is accompanied by a vast ecosystem, including powerful frameworks such as Next, state management libraries (like Mobx), routing solutions (like React Router), and more. Vanilla JavaScript, while powerful and flexible, typically requires more configurations and glue code to achieve similar functionality.

By using React, developers can build more robust and maintainable applications. As you dive deeper into React throughout this course, you'll learn not just how to create interactive elements, but also how to structure large applications, manage state more effectively, and optimize performance. This introduction sets the stage for an in-depth exploration of React's capabilities and how they can be harnessed to create better web experiences.

In the next section we will install React in our project and start working on our assignment.

Maggie

Discuss with Maggie
Use the power of generative AI to interact with course content

Discussion

0 comments
Loading editor ...
Remember to be polite and report any undesirable behaviour

Category

Empty

Labels

Discussion has no labels

1 participant

user avatar

Priority

Notifications

You're not receiving notifications from this thread.
Course Outline