React Fundamentals Part 1
React Fundamentals Part 1
❏ Name
❏ Major
❏ Job
❏ Objectives of Enrolling at Web
Nanaodegree.
2.Easy to use
React it's a JavaScript library that enables developers to quickly and efficiently build
interactive and dynamic user interfaces with minimal coding.
❏ fetch('/', {
// configuration}).then(response => response.json()).then(response => {
// do something with data})
// ES6
const multiplyES6 = (x, y)
=> { return x * y }
or
const multiplyES6 = (x, y)
=> (x * y ) .
What’s React
A JavaScript library for building user interfaces
React Features:
It uses VirtualDOM instead of RealDOM considering that RealDOM
manipulations are expensive.
Supports server-side rendering.
Follows Unidirectional data flow or data binding.
Uses reusable/composable UI components to develop the view.
Javascript Libraries and Frameworks
Example
.
DOM
Workbox
With a function component, this element is the object that the function
returns. With a class component, the element is the object that the
component’s render function returns.
React elements are not what we see in the browser. They are just objects in
memory and we can’t change anything about them.
React.createElement(React Without JSX)
• Create and return a new React element of
the given type.
React.createElement JSX
JSX: JavaScript in XML
JSX is an XML-like syntax extension to ECMAScript
The purpose of this specification is to define a concise and familiar syntax for
defining tree structures with attributes.
React
Types of React Components
What are React Components?
React components are independent and reusable code. They are the building
blocks of any React application. Components serve the same purpose as
JavaScript functions, but work individually to return JSX code as elements for
our UI. Components usually come in two types, functional components and
class components, but today we will also be talking about pure components
and higher-order components.
Types of React Components
Functional Components
Functional components are functions that takes in props and return JSX. They do not
natively have state or lifecycle methods,
but this functionality can be added by implementing React Hooks. Functional
components are usually used to display information. They are easy to read, debug,
and test.
Class Components
Class components have previously been the most commonly used among the four
component types. This is because class components are able to do everything a
functional component do but more. It can utilize the main functions of React, state,
props, and lifecycle methods. Unlike functional components, class components are
consist of … well, a class.
Officially you can't use hook on class component
Types of React Components
Since the React 16.8 update which added hooks to function components, you
might have seen function components replacing class components
everywhere.
Uncontrolled Components
Uncontrolled components act more like traditional HTML form elements. The
data for each input element is stored in the DOM, not in the component.
Instead of writing an event handler for all of your state updates, you use a ref
to retrieve values from the DOM.
Create React App
Facebook's create-react-app is a command-line tool that scaffolds a React
application.
Using this, there is no need to install or configure module bundlers like
Webpack, or transpilers like Babel.
These come preconfigured (and hidden) with create-react-app, so you can
jump right into building your app!