SlideShare a Scribd company logo
1 of 68
Download to read offline
Wprowadzenie
do ReactJS
DreamLab Academy // Kamil Wojtanowski, Marek Mitis
2
First Application
3
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<div>Hello</div>,
document.getElementById('root')
);
First Application
4
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<div>Hello</div>,
document.getElementById('root')
);
First Application
5
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<div>Hello</div>,
document.getElementById('root')
);
Base Application
6
Controllers
Services
Templates
Models
Base Application
7
Controllers
Services
Templates
Models
Components
Sample Application
8
Sample Application
9
Sample Application
10
First Application
11
import React from 'react';
import ReactDOM from 'react-dom';
ReactDOM.render(
<div>Hello</div>,
document.getElementById('root')
);
ReactDOM is the glue
between React and the DOM
Example component
12
import React from 'react';
export function TodoApp() {
return (
<h1>Learn React</h1>
);
}
export default TodoApp;
Example component
13
import React from 'react';
export function TodoApp() {
return (
<h1>Learn React</h1>
);
}
export default TodoApp;
Example component
14
import React from 'react';
export function TodoApp() {
return (
<h1>Learn React</h1>
);
}
export default TodoApp;
import React from 'react';
export class TodoApp extends React.Component {
render() {
return (
<h1>Learn React</h1>
);
}
}
export default TodoApp;
15
Hooks
16
Dummy/not dummy
17
export function TodoApp() {
return (
<h1>Learn React</h1>
);
}
XML?
18
JSX
19
export function TodoApp() {
return (
<h1>Learn React</h1>
);
}
function TodoApp() {
return React.createElement(
"h1",
null,
"Learn React"
);
}
Compilation
Props
20
function TodoApp({task}) {
return (
<h1>{task}</h1>
);
}
<TodoApp task={"Learn React"}/>
Props
21
function TodoApp({task}) {
return (
<h1>{task}</h1>
);
}
<TodoApp task={"Learn React"}/>
class TodoApp extends React.Component {
render() {
return (
<h1>{this.props.task}</h1>
);
}
}
Props
22
class TodoApp extends React.Component {
render() {
this.props.task = 'New task';
return (
<h1>{this.props.task}</h1>
);
}
}
Props are immutable
23
class TodoApp extends React.Component {
render() {
this.props.task = 'New task';
return (
<h1>{this.props.task}</h1>
);
}
}
Props are immutable
24
class TodoApp extends React.Component {
constructor(props) {
super(props);
this.state = {
task: 'Learn React'
}
}
render() {
return (
<h1>{this.state.task}</h1>
);
}
}
State
25
State
26
class TodoApp extends React.Component {
constructor(props) {
super(props);
this.state = {
task: 'Learn React'
}
}
render() {
return (
<h1>{this.state.task}</h1>
);
}
}
addNewTask() {
this.setState({
task: 'My new task’
});
}
State is mutable
27
28
ContextAPI
addTask(e) {
...
}
render() {
return (
<form onSubmit={this.addTask}>
...
</form>
);
}
Events
29
addTask(e) {
...
}
render() {
return (
<form onSubmit={this.addTask}>
...
</form>
);
}
Events
30
addTask(e) {
...
}
render() {
return (
<form onSubmit={this.addTask}>
...
</form>
);
}
Events
31
addTask(e) {
e.preventDefault();
}
render() {
return (
<form onSubmit={this.addTask}>
...
</form>
);
}
Events
32
Child components
33
import TodoList from './TodoList';
export class TodoApp extends React.Component {
render() {
return (
<div>
...
<TodoList items={this.state.items} />
</div>
);
}}
Child components
34
import TodoList from './TodoList';
export class TodoApp extends React.Component {
render() {
return (
<div>
...
<TodoList items={this.state.items} />
</div>
);
}}
Render multiple components
35
render() {
return (
<ul>
{this.props.items.map((item) => {
return (
<li key={item.id}>{item.text}</li>
)
})}
</ul>
)
}
36
{children}
Render multiple components
37
render() {
return (
<ul>
{this.props.items.map((item) => {
return (
<li key={item.id}>{item.text}</li>
)
})}
</ul>
)
}
import React, {PropTypes} from 'react';
export class TodoList extends React.Component {
...
}
TodoList.propTypes = {
items: PropTypes.arrayOf(PropTypes.string)
};
Typechecking with PropTypes
38
import React from 'react';
export class TodoList extends React.Component {
...
}
TodoList.propTypes = {
items: PropTypes.arrayOf(PropTypes.string)
};
Typechecking with PropTypes
39
Component Lifecycle
40
constructor()
getDerivedStateFromProps()
render()
componentDidMount()
getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
componentWillUnmount()
componentDidCatch()
Component Lifecycle
41
constructor()
getDerivedStateFromProps()
render()
componentDidMount()
getDerivedStateFromProps()
shouldComponentUpdate()
render()
getSnapshotBeforeUpdate()
componentDidUpdate()
componentWillUnmount()
componentDidCatch()
42
Wady?
43
Inny framework?
44
Społeczność?
45
Społeczność
46
Podsumowanie
47
Components
48
JSX
49
r
State/Props
50
Events
51
Lifecycle
DreamLab – hub technologiczny Ringier Axel Springer
Warsztaty
53
http://tiny.cc/kadq4y
DreamLab – hub technologiczny Ringier Axel Springer
Quiz
55
Ile gwiazdek na platformie GitHub posiada
rezpozytorium React?
A) 126k
B) 86k
C) 111k
D) 67k
56
Ile gwiazdek na platformie GitHub posiada
rezpozytorium React?
A) 126k
B) 86k
C) 111k
D) 67k
57
Jaka metoda nie występuje w cyklu życia komponentu
React?
A) componentDidMount
B) componentUpdate
C) componentWillUnmount
D) shouldComponentUpdate
58
Jaka metoda nie występuje w cyklu życia komponentu
React?
A) componentDidMount
B) componentUpdate
C) componentWillUnmount
D) shouldComponentUpdate
59
Za pomocą jakiego stałego props’a wyświetlić
elementy owrapowane przez komponent?
A) slots
B) notes
C) children
D) content
60
Za pomocą jakiego stałego props’a wyświetlić
elementy owrapowane przez komponent?
A) slots
B) notes
C) children
D) content
61
Jakie rozwiązanie stanowi o wysokiej wydajności
React’a?
A) NativeDOM
B) DOM
C) VirtualDOM
D) ShadowDOM
62
Jakie rozwiązanie stanowi o wysokiej wydajności
React’a?
A) NativeDOM
B) DOM
C) VirtualDOM
D) ShadowDOM
63
Jaki atrybut pozwala na optymalizacje renderowania
w momencie wyświetlania danych tablicowych?
A) id
B) key
C) order
D) unique
64
Jaki atrybut pozwala na optymalizacje renderowania
w momencie wyświetlania danych tablicowych?
A) id
B) key
C) order
D) unique
65
Jakie działania nie powodują przerenderowanie
elementu?
A) Zmiana zewnętrznych propsów
B) Metoda forceUpdate
C) Metoda applyRender
D) Metoda setState
66
Jakie działania nie powodują przerenderowanie
elementu?
A) Zmiana zewnętrznych propsów
B) Metoda forceUpdate
C) Metoda applyRender
D) Metoda setState
67
Na jakie wywołanie w React transpilowany jest
pojedynczy znacznik z JSX?
A) React.createNode
B) React.createElement
C) new React.Element
D) new React.Node
68
Na jakie wywołanie w React transpilowany jest
pojedynczy znacznik z JSX?
A) React.createNode
B) React.createElement
C) new React.Element
D) new React.Node

More Related Content

More from DreamLab

Selenium WebDriver Testy Automatyczne w Pythonie | DreamLab Academy #8
Selenium WebDriver Testy Automatyczne w Pythonie | DreamLab Academy #8Selenium WebDriver Testy Automatyczne w Pythonie | DreamLab Academy #8
Selenium WebDriver Testy Automatyczne w Pythonie | DreamLab Academy #8DreamLab
 
Intro to React | DreamLab Academy
Intro to React | DreamLab AcademyIntro to React | DreamLab Academy
Intro to React | DreamLab AcademyDreamLab
 
Subtelna sztuka optymalizacji
Subtelna sztuka optymalizacji Subtelna sztuka optymalizacji
Subtelna sztuka optymalizacji DreamLab
 
Podstawy JavaScript | DreamLab Academy #7
Podstawy JavaScript | DreamLab Academy #7Podstawy JavaScript | DreamLab Academy #7
Podstawy JavaScript | DreamLab Academy #7DreamLab
 
Let's build a PaaS platform, how hard could it be?
Let's build a PaaS platform, how hard could it be?Let's build a PaaS platform, how hard could it be?
Let's build a PaaS platform, how hard could it be?DreamLab
 
Wdrażanie na wulkanie, czyli CI w świecie który nie znosi opóźnień.
Wdrażanie na wulkanie, czyli CI w świecie który nie znosi opóźnień.Wdrażanie na wulkanie, czyli CI w świecie który nie znosi opóźnień.
Wdrażanie na wulkanie, czyli CI w świecie który nie znosi opóźnień.DreamLab
 
Gdy testy to za mało - Continuous Monitoring
Gdy testy to za mało - Continuous MonitoringGdy testy to za mało - Continuous Monitoring
Gdy testy to za mało - Continuous MonitoringDreamLab
 
Intro to JavaScript | Wstęp do programowania w Java Script | DreamLab Academy #4
Intro to JavaScript | Wstęp do programowania w Java Script | DreamLab Academy #4Intro to JavaScript | Wstęp do programowania w Java Script | DreamLab Academy #4
Intro to JavaScript | Wstęp do programowania w Java Script | DreamLab Academy #4DreamLab
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 DreamLab
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2DreamLab
 
About Motivation in DevOps Culture
About Motivation in DevOps CultureAbout Motivation in DevOps Culture
About Motivation in DevOps CultureDreamLab
 
Continuous Integration w konfiguracji urządzeń sieciowych
Continuous Integration w konfiguracji urządzeń sieciowychContinuous Integration w konfiguracji urządzeń sieciowych
Continuous Integration w konfiguracji urządzeń sieciowychDreamLab
 
Real User Monitoring at Scale @ Atmosphere Conference 2016
Real User Monitoring at Scale @ Atmosphere Conference 2016Real User Monitoring at Scale @ Atmosphere Conference 2016
Real User Monitoring at Scale @ Atmosphere Conference 2016DreamLab
 
DevOps at DreamLab
DevOps at DreamLabDevOps at DreamLab
DevOps at DreamLabDreamLab
 

More from DreamLab (14)

Selenium WebDriver Testy Automatyczne w Pythonie | DreamLab Academy #8
Selenium WebDriver Testy Automatyczne w Pythonie | DreamLab Academy #8Selenium WebDriver Testy Automatyczne w Pythonie | DreamLab Academy #8
Selenium WebDriver Testy Automatyczne w Pythonie | DreamLab Academy #8
 
Intro to React | DreamLab Academy
Intro to React | DreamLab AcademyIntro to React | DreamLab Academy
Intro to React | DreamLab Academy
 
Subtelna sztuka optymalizacji
Subtelna sztuka optymalizacji Subtelna sztuka optymalizacji
Subtelna sztuka optymalizacji
 
Podstawy JavaScript | DreamLab Academy #7
Podstawy JavaScript | DreamLab Academy #7Podstawy JavaScript | DreamLab Academy #7
Podstawy JavaScript | DreamLab Academy #7
 
Let's build a PaaS platform, how hard could it be?
Let's build a PaaS platform, how hard could it be?Let's build a PaaS platform, how hard could it be?
Let's build a PaaS platform, how hard could it be?
 
Wdrażanie na wulkanie, czyli CI w świecie który nie znosi opóźnień.
Wdrażanie na wulkanie, czyli CI w świecie który nie znosi opóźnień.Wdrażanie na wulkanie, czyli CI w świecie który nie znosi opóźnień.
Wdrażanie na wulkanie, czyli CI w świecie który nie znosi opóźnień.
 
Gdy testy to za mało - Continuous Monitoring
Gdy testy to za mało - Continuous MonitoringGdy testy to za mało - Continuous Monitoring
Gdy testy to za mało - Continuous Monitoring
 
Intro to JavaScript | Wstęp do programowania w Java Script | DreamLab Academy #4
Intro to JavaScript | Wstęp do programowania w Java Script | DreamLab Academy #4Intro to JavaScript | Wstęp do programowania w Java Script | DreamLab Academy #4
Intro to JavaScript | Wstęp do programowania w Java Script | DreamLab Academy #4
 
Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3 Intro to Redux | DreamLab Academy #3
Intro to Redux | DreamLab Academy #3
 
Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2Quick start with React | DreamLab Academy #2
Quick start with React | DreamLab Academy #2
 
About Motivation in DevOps Culture
About Motivation in DevOps CultureAbout Motivation in DevOps Culture
About Motivation in DevOps Culture
 
Continuous Integration w konfiguracji urządzeń sieciowych
Continuous Integration w konfiguracji urządzeń sieciowychContinuous Integration w konfiguracji urządzeń sieciowych
Continuous Integration w konfiguracji urządzeń sieciowych
 
Real User Monitoring at Scale @ Atmosphere Conference 2016
Real User Monitoring at Scale @ Atmosphere Conference 2016Real User Monitoring at Scale @ Atmosphere Conference 2016
Real User Monitoring at Scale @ Atmosphere Conference 2016
 
DevOps at DreamLab
DevOps at DreamLabDevOps at DreamLab
DevOps at DreamLab
 

DreamLab Academy #12 Wprowadzenie do React.js