KEMBAR78
React + Redux + TypeScript === ♥ | PPTX
React + Redux + TypeScript === ♥
An introduction to the development of universal JavaScript
applications with React, Redux & TypeScript
By Remo H. Jansen
Live demo & source code
https://github.com/remojansen/typescript-redux-react-demo
React
A JavaScript library for building user interfaces.
Lots of people use React as the V in MVC.
Makes no assumptions about the rest of your technology stack.
Abstracts away the DOM from you.
Can also render on the server using Node.
Can power native apps using React Native.
One-way reactive data flow.
React.Component
Components are the main building block of a React application.
A component represents a self-contained piece of UI.
Display some data and be able handle some kind of user interaction.
A component can contain child components.
React.Component: Properties
Properties are a Component's configuration. Received from above and immutable..
React.Component: Life cycle
Everything is a tree!
Properties (JSON):
Components (JSX/TSX)
Output (HTML)
React.Component: State, JSX/TSX and Events
The state starts with a default value when a Component mounts.
The state suffers from mutations in time (mostly generated from user events).
A Component manages its own state internally (you could say the state is private).
React.Component: The state problem
The Problem:
Managing the internal state of the components makes them hard to maintain.
Components stop being a “pure function” when we use state: (porps) => HTML
The solution:
Move the state to the parent component and inject it as properties.
Inject properties from the top of the component’s hierarchy.
Redux
Predictable state container for
JavaScript apps.
Applications that behave
consistently.
Run in client, server, and native
easy to test.
Great developer experience.
Unidirectional data flow.
Making the state “global”: The Store
Making the state “global”: The provider
The provider owns the store and makes the it
available to other components (in the
component hierarchy below) using the
@connect() calls.
Redux: @Connect
Components decorated with @connect
are aware of the Store and because of
that we call them smart components.
Dumb components receive their
properties from its parent component
and are not aware of the Store.
Smart components are less reusable.
Redux: Actions and action creators
An action creator is just a function that returns an action (a JSON object). Actions
must have an action type:
Using the makeActionCreator helper:
Redux: Reducers
Actions describe the fact that something happened, but don’t specify how the
application’s state changes in response. This is the job of a reducer.
(Previous State, Action) => new
State
Redux: Summary
The Redux ecosystem: Asynchronous actions
Thunk middleware for Redux https://github.com/gaearon/redux-thunk
The Redux ecosystem: Router
React router for Redux https://github.com/rackt/react-router-redux
The Redux ecosystem: Development tools
Redux Devtools
https://github.com/zalmoxisus/redux-
devtools-extension
React Hot Loader
http://gaearon.github.io/react-hot-
loader/
Questions?
Thanks!
Contact me at www.remojansen.com or @OweR_ReLoaDeD

React + Redux + TypeScript === ♥

  • 1.
    React + Redux+ TypeScript === ♥ An introduction to the development of universal JavaScript applications with React, Redux & TypeScript By Remo H. Jansen
  • 2.
    Live demo &source code https://github.com/remojansen/typescript-redux-react-demo
  • 3.
    React A JavaScript libraryfor building user interfaces. Lots of people use React as the V in MVC. Makes no assumptions about the rest of your technology stack. Abstracts away the DOM from you. Can also render on the server using Node. Can power native apps using React Native. One-way reactive data flow.
  • 4.
    React.Component Components are themain building block of a React application. A component represents a self-contained piece of UI. Display some data and be able handle some kind of user interaction. A component can contain child components.
  • 5.
    React.Component: Properties Properties area Component's configuration. Received from above and immutable..
  • 6.
  • 7.
    Everything is atree! Properties (JSON): Components (JSX/TSX) Output (HTML)
  • 8.
    React.Component: State, JSX/TSXand Events The state starts with a default value when a Component mounts. The state suffers from mutations in time (mostly generated from user events). A Component manages its own state internally (you could say the state is private).
  • 9.
    React.Component: The stateproblem The Problem: Managing the internal state of the components makes them hard to maintain. Components stop being a “pure function” when we use state: (porps) => HTML The solution: Move the state to the parent component and inject it as properties. Inject properties from the top of the component’s hierarchy.
  • 10.
    Redux Predictable state containerfor JavaScript apps. Applications that behave consistently. Run in client, server, and native easy to test. Great developer experience. Unidirectional data flow.
  • 11.
    Making the state“global”: The Store
  • 12.
    Making the state“global”: The provider The provider owns the store and makes the it available to other components (in the component hierarchy below) using the @connect() calls.
  • 13.
    Redux: @Connect Components decoratedwith @connect are aware of the Store and because of that we call them smart components. Dumb components receive their properties from its parent component and are not aware of the Store. Smart components are less reusable.
  • 14.
    Redux: Actions andaction creators An action creator is just a function that returns an action (a JSON object). Actions must have an action type: Using the makeActionCreator helper:
  • 15.
    Redux: Reducers Actions describethe fact that something happened, but don’t specify how the application’s state changes in response. This is the job of a reducer. (Previous State, Action) => new State
  • 16.
  • 17.
    The Redux ecosystem:Asynchronous actions Thunk middleware for Redux https://github.com/gaearon/redux-thunk
  • 18.
    The Redux ecosystem:Router React router for Redux https://github.com/rackt/react-router-redux
  • 19.
    The Redux ecosystem:Development tools Redux Devtools https://github.com/zalmoxisus/redux- devtools-extension React Hot Loader http://gaearon.github.io/react-hot- loader/
  • 20.
  • 21.
    Thanks! Contact me atwww.remojansen.com or @OweR_ReLoaDeD

Editor's Notes

  • #5 Think about an online chess game made in HTML. Think about one of the cells in the game board. The cell represents a self-contained piece of UI and therefore can be implemented as a React component. We could represent the cell and a contained figure using the following HTML. That HTML is going to be generated by a React component.