SlideShare a Scribd company logo
1 of 19
Download to read offline
WITAMY!
WARSAW REACT.JS #1
REACT.JS WARSAW #1
AGENDA
▸ Przywitanie sponsora - ASTEK Polska
▸ React.js - Wprowadzenie - Marcin Mieszek
▸ Flux - intro i przykłady wykorzystania - Damian Legawiec
▸ Losowanie nagrody
▸ W trakcie:
REACT.JS - WPROWADZENIE
WARSAW REACT.JS #1
MARCIN MIESZEK
MARCIN.MIESZEK@GMAIL.COM
REACT.JS WARSAW #1
AGENDA
▸ Czym jest React.js?
▸ Tworzenie komponentów
▸ Warsztaty
REACT.JS WARSAW #1
CZYM JEST REACT.JS?
▸ Deklaratywne komponenty
▸ Virtual DOM
▸ JSX
▸ Jednokierunkowy przepływ danych
REACT.JS WARSAW #1
{name: 'Zaprosić uczestników'},

{name: 'Kupić piwo'},

{name: 'Przygotować prezentację'}

<table>

<tbody>

<tr>

<td><input type="checkbox"></td>

<td>Zaprosić uczestników</td>

</tr>

<tr>

<td><input type="checkbox"></td>

<td>Kupić piwo</td>

</tr>

<tr>

<td><input type="checkbox"></td>

<td>Przygotować prezentację</td>

</tr>

</tbody>

</table>
{name: 'Przywitać gości'}
REACT.JS WARSAW #1
$("button").click(function(){

$("<tr>" +

"<td><input type='checkbox'></td>" +

"<td>Przywitać gości</td>" +

"</tr>").appendTo("tbody");

});



<tr ng-repeat="task in tasks">

<td><input type='checkbox'></td>

<td>{{task.name}}</td>

</tr>
REACT.JS WARSAW #1
DEKLARATYWNE KOMPONENTY
var Tasks = React.createClass({

render: function () {

return (

<table>

<tbody>

{this.props.tasks.map(function (task) {

return (

<tr>

<td><input type="checkbox"/></td>

<td>{task.name}</td>

</tr>

)

})}

</tbody>

</table>

)

}

})
ReactDOM.render(<Tasks tasks={tasks}/>, document.getElementById('app'))
REACT.JS WARSAW #1
JSX
<p class="lead">Hello, world!</p>
React.createElement('p',
{className: 'lead'},
['Hello, world!’]
)
<table>

<tbody>

{this.props.tasks.map(function (task) {

return (

<tr>

<td><input type="checkbox"/></td>

<td>{task.name}</td>

</tr>

)

})}

</tbody>

</table>
React.createElement("table", null,

React.createElement("tbody", null,

this.props.tasks.map(function (task) {

return (

React.createElement("tr", null,

React.createElement("td", null, 

React.createElement("input", {type:
"checkbox"})),

React.createElement("td", null, task.name)

)

)

})

)

)

REACT.JS WARSAW #1
JSX
<table>

<tbody>

{this.state.tasks.map(function (task,) {

return (

<Task task={task}/>

)

}}

var Task = React.createClass({

render: function () {

return (

<tr>

<td><input type="checkbox"/></td>

<td>{this.props.task.name}</td>

</tr>

)

}

})
REACT.JS WARSAW #1
VIRTUAL DOM
▸ Operacje na DOM są kosztowne
▸ Celem jest aktualizacja tylko zmienionych elementów
▸ Renderujemy w pamięci nowy komponent
▸ Znajdowana jest minimalna liczba operacji
transformujących stary komponent w nowy
▸ Nanieśmy zmiany w DOM w jednej serii
REACT.JS WARSAW #1
PRZEPŁYW DANYCH
▸ Dane płyną w dół
▸ Zdarzenia płyną w górę
REACT.JS WARSAW #1
PRACA Z REACT.JS
▸ Komponenty
▸ State, props, refs
▸ Cykl życia
REACT.JS WARSAW #1
KOMPONENTY


var Task = React.createClass({

render: function () {

return (

<tr>

<td><input type="checkbox"/></td>

<td>{this.props.task.name}</td>

</tr>

)

}

})
REACT.JS WARSAW #1
STATE & PROPS
▸ Komponent pobiera dane z props
▸ State przechowuje dane zmienione przez zdarzenia
komponentu
▸ State nie przechowuje:
▸ innych komponentów
▸ kopii props
▸ danych obliczeniowych
REACT.JS WARSAW #1
REFS
<input ref="myInput" />
var input = this.refs.myInput

var inputValue = input.value

var inputRect = input.getBoundingClientRect()
REACT.JS WARSAW #1
CHILDREN
<Parent><Child /></Parent>
<div>

{this.props.children}

</div>
REACT.JS WARSAW #1
CYKL ŻYCIA
▸ ReactElement render
▸ object getInitialState
▸ object getDefaultProps
▸ void componentDidMount
▸ void componentWillReceiveProps(nextProps)
▸ boolean shouldComponentUpdate(nextProps, nextState)
REACT.JS WARSAW #1
WARSZTATY - TO-DO LIST

More Related Content

Featured

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at WorkGetSmarter
 

Featured (20)

How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 

React.js - Wprowadzenie

  • 2. REACT.JS WARSAW #1 AGENDA ▸ Przywitanie sponsora - ASTEK Polska ▸ React.js - Wprowadzenie - Marcin Mieszek ▸ Flux - intro i przykłady wykorzystania - Damian Legawiec ▸ Losowanie nagrody ▸ W trakcie:
  • 3. REACT.JS - WPROWADZENIE WARSAW REACT.JS #1 MARCIN MIESZEK MARCIN.MIESZEK@GMAIL.COM
  • 4. REACT.JS WARSAW #1 AGENDA ▸ Czym jest React.js? ▸ Tworzenie komponentów ▸ Warsztaty
  • 5. REACT.JS WARSAW #1 CZYM JEST REACT.JS? ▸ Deklaratywne komponenty ▸ Virtual DOM ▸ JSX ▸ Jednokierunkowy przepływ danych
  • 6. REACT.JS WARSAW #1 {name: 'Zaprosić uczestników'},
 {name: 'Kupić piwo'},
 {name: 'Przygotować prezentację'}
 <table>
 <tbody>
 <tr>
 <td><input type="checkbox"></td>
 <td>Zaprosić uczestników</td>
 </tr>
 <tr>
 <td><input type="checkbox"></td>
 <td>Kupić piwo</td>
 </tr>
 <tr>
 <td><input type="checkbox"></td>
 <td>Przygotować prezentację</td>
 </tr>
 </tbody>
 </table> {name: 'Przywitać gości'}
  • 7. REACT.JS WARSAW #1 $("button").click(function(){
 $("<tr>" +
 "<td><input type='checkbox'></td>" +
 "<td>Przywitać gości</td>" +
 "</tr>").appendTo("tbody");
 });
 
 <tr ng-repeat="task in tasks">
 <td><input type='checkbox'></td>
 <td>{{task.name}}</td>
 </tr>
  • 8. REACT.JS WARSAW #1 DEKLARATYWNE KOMPONENTY var Tasks = React.createClass({
 render: function () {
 return (
 <table>
 <tbody>
 {this.props.tasks.map(function (task) {
 return (
 <tr>
 <td><input type="checkbox"/></td>
 <td>{task.name}</td>
 </tr>
 )
 })}
 </tbody>
 </table>
 )
 }
 }) ReactDOM.render(<Tasks tasks={tasks}/>, document.getElementById('app'))
  • 9. REACT.JS WARSAW #1 JSX <p class="lead">Hello, world!</p> React.createElement('p', {className: 'lead'}, ['Hello, world!’] ) <table>
 <tbody>
 {this.props.tasks.map(function (task) {
 return (
 <tr>
 <td><input type="checkbox"/></td>
 <td>{task.name}</td>
 </tr>
 )
 })}
 </tbody>
 </table> React.createElement("table", null,
 React.createElement("tbody", null,
 this.props.tasks.map(function (task) {
 return (
 React.createElement("tr", null,
 React.createElement("td", null, 
 React.createElement("input", {type: "checkbox"})),
 React.createElement("td", null, task.name)
 )
 )
 })
 )
 )

  • 10. REACT.JS WARSAW #1 JSX <table>
 <tbody>
 {this.state.tasks.map(function (task,) {
 return (
 <Task task={task}/>
 )
 }}
 var Task = React.createClass({
 render: function () {
 return (
 <tr>
 <td><input type="checkbox"/></td>
 <td>{this.props.task.name}</td>
 </tr>
 )
 }
 })
  • 11. REACT.JS WARSAW #1 VIRTUAL DOM ▸ Operacje na DOM są kosztowne ▸ Celem jest aktualizacja tylko zmienionych elementów ▸ Renderujemy w pamięci nowy komponent ▸ Znajdowana jest minimalna liczba operacji transformujących stary komponent w nowy ▸ Nanieśmy zmiany w DOM w jednej serii
  • 12. REACT.JS WARSAW #1 PRZEPŁYW DANYCH ▸ Dane płyną w dół ▸ Zdarzenia płyną w górę
  • 13. REACT.JS WARSAW #1 PRACA Z REACT.JS ▸ Komponenty ▸ State, props, refs ▸ Cykl życia
  • 14. REACT.JS WARSAW #1 KOMPONENTY 
 var Task = React.createClass({
 render: function () {
 return (
 <tr>
 <td><input type="checkbox"/></td>
 <td>{this.props.task.name}</td>
 </tr>
 )
 }
 })
  • 15. REACT.JS WARSAW #1 STATE & PROPS ▸ Komponent pobiera dane z props ▸ State przechowuje dane zmienione przez zdarzenia komponentu ▸ State nie przechowuje: ▸ innych komponentów ▸ kopii props ▸ danych obliczeniowych
  • 16. REACT.JS WARSAW #1 REFS <input ref="myInput" /> var input = this.refs.myInput
 var inputValue = input.value
 var inputRect = input.getBoundingClientRect()
  • 17. REACT.JS WARSAW #1 CHILDREN <Parent><Child /></Parent> <div>
 {this.props.children}
 </div>
  • 18. REACT.JS WARSAW #1 CYKL ŻYCIA ▸ ReactElement render ▸ object getInitialState ▸ object getDefaultProps ▸ void componentDidMount ▸ void componentWillReceiveProps(nextProps) ▸ boolean shouldComponentUpdate(nextProps, nextState)