+ All Categories
Home > Engineering > React & ES6 Intro

React & ES6 Intro

Date post: 10-Jan-2017
Category:
Upload: yair-aviner
View: 175 times
Download: 1 times
Share this document with a friend
49
The React Single Page App
Transcript
Page 1: React & ES6 Intro

The React Single Page App

Page 2: React & ES6 Intro

React

What is React?

Page 3: React & ES6 Intro

React

An OSS view library built and maintained by Facebook

Page 4: React & ES6 Intro

React

The ‘view’ is built out of components that are nestable and re-usable

Page 5: React & ES6 Intro

React

Page 6: React & ES6 Intro

React

Page 7: React & ES6 Intro

React

Page 8: React & ES6 Intro

React

Page 9: React & ES6 Intro

React

Page 10: React & ES6 Intro

React

React calls ‘render’ every time state or props is changed.But it’s only making DOM updates for whatever needs to

change.It does the diff for this via the vDOM – virtual DOM.

Page 11: React & ES6 Intro

React

Page 12: React & ES6 Intro

React

Page 13: React & ES6 Intro

React

Page 14: React & ES6 Intro

React

Page 15: React & ES6 Intro

React

Complex components without composition are unwieldy.Use composition.

Page 16: React & ES6 Intro

React

In fact, the whole Single Page App architecture is one component that composes the rest of the

app.

Page 17: React & ES6 Intro

React

So what happens when things become really complex?

Page 18: React & ES6 Intro

React

What happens when components need to talk to each other?

Or when the actions of Component A affect component B?

Page 19: React & ES6 Intro
Page 20: React & ES6 Intro

React

Direct inter-component communication is messy and hard to manage.

Let’s take advantage of the fact that our components are declarative.

Page 21: React & ES6 Intro

React

Basic Solution Shared data should belong to the common ancestor of

two or more components. The ancestor controls the data and defines functions which can modify the data.

Whenever the data updates, the ancestor re-renders itself, in turn re-rendering its children, which will now have new

props passed to them.

Page 22: React & ES6 Intro

React

How do our components access the modifier functions? Remember that in Javascript functions are first-class

citizens.

We simply pass the modifier functions down as props for the children to call as needed.

Page 23: React & ES6 Intro

React

Page 24: React & ES6 Intro

React

Page 25: React & ES6 Intro

React

In a nutshell, this is the pattern for the Single Page App.There’s a whole tree of components, and, in general, they all inherit their state and whatever actions are

needed to change state from the root level.

We call that top level the store. And there’s just one for the whole app.

Page 26: React & ES6 Intro

Redux

Redux – Atomic State Management

Page 27: React & ES6 Intro

Redux

Redux is a Flux-inspired library for creating and managing our global app state.

At a basic level it provides access to the global state as well asa dispatcher that accepts actions.

Page 28: React & ES6 Intro

Redux, or Flux

Page 29: React & ES6 Intro

Redux

We’ll come back to how this ties together in the code soon.There’s a couple other concepts to cover first.

Page 30: React & ES6 Intro

React-Router

First, React Router. It’s a small library that gives us client-side routing with pretty URLs. It works by matching routes to

determine which components should be displayed.

Page 31: React & ES6 Intro

React-Router

Page 32: React & ES6 Intro

ES2015/ES2016

Also on the detour: New Javascript!

Page 33: React & ES6 Intro

ES2015/ES2016

You’ll see this interchangeably as ES2015/2016 or ES6/ES7. Either way, it refers to new additions to Javascript.

Page 34: React & ES6 Intro

ES2015/ES2016

Page 35: React & ES6 Intro

ES2015/ES2016

Page 36: React & ES6 Intro

ES2015/ES2016

Page 37: React & ES6 Intro

ES2015/ES2016

Page 38: React & ES6 Intro

ES2015/ES2016

Using const and let provides useful signals to the dev and the interpreter about the intended use of the variable.

There’s no instance where ‘var’ is preferable to either.

Page 39: React & ES6 Intro

ES2015/ES2016

Page 40: React & ES6 Intro

ES2015/ES2016

Page 41: React & ES6 Intro

ES2015/ES2016

Page 42: React & ES6 Intro

ES2015/ES2016

Page 43: React & ES6 Intro

ES2015/ES2016

Page 44: React & ES6 Intro

ES2015/ES2016

Page 45: React & ES6 Intro

ES2015/ES2016

Page 46: React & ES6 Intro

ES2015/ES2016

We can use all this today!Browser Compatibility solved with Babel

Page 47: React & ES6 Intro

Walkthrough

Here there was a walkthrough of the specific app architecture / structure used in the project… skipping.

Page 48: React & ES6 Intro

Post Walkthrough

Some important notes:

• Component render functions should be pure functions and simple.• The Redux store must be immutable. We can enforce this with

libraries.• Reducers and action creators should be pure (no side effects).• Not everything needs to live in the global redux store – just data

that is important to the application flow or to multiple components. UI state for a single component does not need to live in the global store.

• Ctrl-H for dev tooling (in dev builds)• Write unit tests for components, action creators, and reducers!

Page 49: React & ES6 Intro

Post Walkthrough

Thank you!Questions?


Recommended