Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
59 views
React in 30 Day
Uploaded by
Nasiru Abdullahi Babatsofo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save React in 30 Day For Later
Download
Save
Save React in 30 Day For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
59 views
React in 30 Day
Uploaded by
Nasiru Abdullahi Babatsofo
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save React in 30 Day For Later
Carousel Previous
Carousel Next
Save
Save React in 30 Day For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 304
Search
Fullscreen
JU DAYS Hi we ATUL a RT SSCA Ne Lacan al 4) Serie ae XenaeA ase ss WHATIS REACT? What is React? © Edit this page on Github (https://githut cact/blob/master/day-01/post.md) Today, we're starting out at the beginning. Let's look at what React is and what makes it tick. We'll discuss why we want to use it. Over the next 30 days, you'll get a good feel for the various parts of the React (https: //facebook.github.io/react/) web framework and its ecosystem, Each day in our 30 day adventure will build upon the previous day's materials, so by the end of the series, you'll not only know the terms, concepts, and underpinnings of how the framework works, but be able to use React in your next web application. Let's get started. We'll start at the very beginning (https: //www.youtube.com/watch?v=IRW3nDRmu6k) as it's a very good place to start. What is React? React (https://facebook.github.io/react/) is a JavaScript library for building user interfaces. It is the view layer for web applications. At the heart of all React applications are components. A component is a self- contained module that renders some output. We can write interface elements like a button or an input field as a React component. Componentsare composable, A component might include one or more other components in its output. Broadly speaking, to write React apps we write React components that correspond to various interface elements. We then organize these components inside higher-level components which define the structure of our application. For example, take a form. A form might consist of many interface elements, like input fields, labels, or buttons. Each element inside the form can be written as a React component. We'd then write a higher-level component, the form component itself. The form component would specify the structure of the form and include each of these interface elements inside of it. Importantly, each component in a React app abides by strict data management principles. Complex, interactive user interfaces often involve complex data and application state. The surface area of React is limited and aimed at giving us the tools to be able to anticipate how our application will look with a given set of circumstances. We dig into these principles later in the course, Okay, so how do we use it? React is a JavaScript framework. Using the framework is as simple as including a JavaScript file in our HTML and using the React exports in our application's JavaScript. For instance, the Hello world example of a React website can be as simple as:RELY; Cao LESS per ae See altars Mec C SSPE sct a9 eRe ee esata //unpkg . com/babel-standalone@é/babel .min.js"> C'#app') Although it might look a little scary, the JavaScript code is a single line that dynamically adds Hello world to the page. Note that we only needed to include a handful of JavaScript files to get everything working. How does it work? Unlike many of its predecessors, React operates not directly on the browser's Document Object Model (DOM) immediately, but on a virtual DOM. That is, rather than manipulating the document in a browser after changes to our data (which can be quite slow) it resolves changes on a DOM built and run entirely in memory. After the virtual DOM has been updated, React intelligently determines what changes to make to the actual browser's DOM.The React Virtual DOM (https: //facebook.github.io/react /docs/dom- differences.html) exists entirely in-memory and is a representation of the web browser's DOM. Because of this, when we write a React component, we're not writing directly to the DOM, but we're writing a virtual component that React will turn into the DOM. In the next article, we'll look at what this means for us as we build our React components and jump into JSX and writing our first real components.BU aed ST WHAT IS JSX? ES6? What is JSX? © Eadie this page on Git Now that we know what React is, let's take a look at a few terms and concepts that will come up throughout the rest of the series. In our previous article, we looked at what React (https: //facebook.github.io/react/) is and discussed at a high-level how it works. In this article, we're going to look at one part of the React ecosystem: ES6 and ISX. JSX/ES5/ES6 WTF??! In any cursory search on the Internet looking for React material, no doubt you have already run into the terms 35x, ES5, and ES6. These opaque acronyms can get confusing quickly. ESS (the es stands for ECMAScript) is basically "regular JavaScript” The 5th update to JavaScript, ES5 was finalized in 2009. It has been supported by all major browsers for several years. Therefore, if you've written or seen any JavaScript in the recent past, chances are it was ES5. ES6 is a new version of JavaScript that adds some nice syntactical and functional additions. It was finalized in 2015. ES6 is almost fully supported (http: //kangax.github.io/compat-table/es6/) by all major browsers. But itwill be some time until older versions of web browsers are phased out of use. For instance, Internet Explorer 11 does not support ES6, but has about 12% of the browser market share. In order to reap the benefits of ES6 today, we have to do a few things to get it to work in as many browsers as we can: 1. We have to transpile our code so that a wider range of browsers understand our JavaScript. This means converting ES6 JavaScript into ESS JavaScript. 2. We have to include a shim or polyfill that provides additional functionality added in ES6 that a browser may or may not have. We'll see how we do this a bit later in the series. Most of the code we'll write in this series will be easily translatable to ES5. In cases where we use ES6, we'll introduce the feature at first and then walk through it. As we'll see, all of our React components have a render function that specifies what the HTML output of our React component will be. JavaScript eXtension, or more commonly JSX, is a React extension that allows us to write JavaScript that looks like HTML. Although in previous paradigms it was viewed as a bad habit to include JavaScript and markup in the same place, it turns out that combining the view with the functionality makes reasoning about the view straight-forward.To see what this means, imagine we had a React component that renders an ht HTML tag, JSX allows us to declare this element in a manner that closely resembles HTML: ore Of peaet eG PURSE Cua eae Hello World The xender() function in the Hellovorld component looks like it's returning HTML, but this is actually JSX. The JSX is translated to regular JavaScript at runtime. That component, after translation, looks like this: Cee Tec sae While JSX looks like HTML, it is actually just a terser way to write a React .createElement() declaration. When a component renders, it outputs a tree of React elements or a virtual representation of the HTML elements this component outputs. React will then determine what changes to make to the actual DOM based on this React element representation. In the case of the HelloWorld component, the HTML that React writes to the DOM will look like thThe class extends syntax we used in our first React component is ES6 s familiar Object-Oriented style. In ESS, the class syntax might be translated as: mtax. It allows us to write obje s using a 5) CSB ae Pee aM rls] 19 Because JSX is JavaScript, we includes words like class and for. n't use JavaScript reserved words. This React gives us the attribute className. We use it in HelloWorld to set the large class on our hi tag. There are a few other attributes, such as the for attribute on a label that React translates into htmlFor as for is alsoa reserved word. We'll look at these when we start using them. If we want to write pure JavaScript instead of rely on a JSX compiler, we ci just write the React.createElement() function and not worry about the layer of abstraction. But we like JSX. It's especially more readable with complex components. Consider the following JSX: tr) Ores stars cen The JavaScript delivered to the browser will look like thiAgain, while you can skip JSX and write the latter directly, the JSX syntax is. well-suited for representing nested HTML elements. Now that we understand JSX, we can start writing our first React components. Join us tomorrow when we jump into our first React app.Bisa STM FIRST COMPONENTS Our First Components © Edit this page on Github (https:/sithut act/blob/master/day-03/post.md) The first two articles in this series were heavy on discussion. In today's session, let's dive into some code and write our first React app. Let's revisit the "Hello world" app we introduced on day one. Here it is again, written slightly differently:caaye Sais er iy SUG ET 74a SEMA CI ESOL SE LAE ULYAc aos UA Cae dom.min.js"> > ht A RL rere VCCI, eS eS eS ey Hello world Loading the React library We've included the source of React as a