SlideShare a Scribd company logo
1 of 31
Download to read offline
React 16: Error Handling
David Slone
Front-End Engineer @ Stem

Twitter @dbslone

Github @dbslone
REACT 16
REACT 16
It’s finally here…almost
What’s New?https://github.com/facebook/react/issues/10294
What’s New?
• Fiber
https://github.com/facebook/react/issues/10294
What’s New?
• Fiber
• Error Boundaries
https://github.com/facebook/react/issues/10294
What’s New?
• Fiber
• Error Boundaries
• Returning arrays from render
https://github.com/facebook/react/issues/10294
What’s New?
• Fiber
• Error Boundaries
• Returning arrays from render
• Lots of other stuff
https://github.com/facebook/react/issues/10294
What’s New?
• Fiber
• Error Boundaries
• Returning arrays from render
• Lots of other stuff
https://github.com/facebook/react/issues/10294
Fiberhttps://github.com/acdlite/react-fiber-architecture
Fiber
• Complete rewrite of the React core
https://github.com/acdlite/react-fiber-architecture
Fiber
• Complete rewrite of the React core
• Unfortunately async render isn’t here yet
https://github.com/acdlite/react-fiber-architecture
Fiber
• Complete rewrite of the React core
• Unfortunately async render isn’t here yet
• https://www.youtube.com/watch?v=Qu_6ItnlDQg
https://github.com/acdlite/react-fiber-architecture
Inefficient Renders
Inefficient Renders
• React uses recursive diff’ing
Inefficient Renders
// Before
render() {
return (
<ul>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
// After
render() {
return (
<ul>
<li>Santa Monica</li>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
• React uses recursive diff’ing
• Inserting at the beginning of the list means
rendering the whole tree again
Inefficient Renders
// Before
render() {
return (
<ul>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
// After
render() {
return (
<ul>
<li>Santa Monica</li>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
• React uses recursive diff’ing
• Inserting at the beginning of the list means
rendering the whole tree again
• Best algorithms have a time complexity O(n3)
Inefficient Renders
// Before
render() {
return (
<ul>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
// After
render() {
return (
<ul>
<li>Santa Monica</li>
<li>Hollywood</li>
<li>Pasadena</li>
</ul>
)
}
• React uses recursive diff’ing
• Inserting at the beginning of the list means
rendering the whole tree again
• Best algorithms have a time complexity O(n3)
• 1000 elements === 1billion comparisons
The Solution?
https://facebook.github.io/react/docs/reconciliation.html
The Solution?
• Heuristics - using shortcuts today to
solve the problems of tomorrow
https://facebook.github.io/react/docs/reconciliation.html
The Solution?
// Before
render() {
return (
<ul>
<li key="Hollywood">Hollywood</li>
<li key="Pasadena">Pasadena</li>
</ul>
)
}
// After
render() {
return (
<ul>
<li key="Santa Monica">Santa Monica</li>
<li key="Hollywood">Hollywood</li>
<li key="Pasadena">Pasadena</li>
</ul>
)
}
• Heuristics - using shortcuts today to
solve the problems of tomorrow
• Using “key” allows React to match
children in the original tree with
children in the subsequent tree
https://facebook.github.io/react/docs/reconciliation.html
The Solution?
// Before
render() {
return (
<ul>
<li key="Hollywood">Hollywood</li>
<li key="Pasadena">Pasadena</li>
</ul>
)
}
// After
render() {
return (
<ul>
<li key="Santa Monica">Santa Monica</li>
<li key="Hollywood">Hollywood</li>
<li key="Pasadena">Pasadena</li>
</ul>
)
}
• Heuristics - using shortcuts today to
solve the problems of tomorrow
• Using “key” allows React to match
children in the original tree with
children in the subsequent tree
• Keys only need to be unique to
siblings not the global scope
https://facebook.github.io/react/docs/reconciliation.html
How is Fiber Different?
How is Fiber Different?
• A fiber is a JavaScript object that contains information
about a component, its input, and its output.
How is Fiber Different?
• A fiber is a JavaScript object that contains information
about a component, its input, and its output.
• Allows delaying the render of components by using a
priority system
Returning arrays
Returning arrays
render() {
return (
<div>Studio City</div>
<div>Century City</div>
)
}
Returning arrays
render() {
return this.props.item.map((item) => (
<li>{item}</li>
))
}
Error Handling
class ErrorBoundary extends React.Component {
constructor(props) {
super(props);
this.state = { hasError: false };
}
componentDidCatch(error, info) {
// Display fallback UI
this.setState({ hasError: true });
// You can also log the error to an error reporting service
logErrorToMyService(error, info);
}
render() {
if (this.state.hasError) {
// You can render any custom fallback UI
return <h1>Something went wrong.</h1>;
}
return this.props.children;
}
}
TIME FOR A DEMO

More Related Content

Similar to React 16: Error Handling

pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)Eugene Yokota
 
Power Up Your Build - Omer van Kloeten @ Wix 2018-04
Power Up Your Build - Omer van Kloeten @ Wix 2018-04Power Up Your Build - Omer van Kloeten @ Wix 2018-04
Power Up Your Build - Omer van Kloeten @ Wix 2018-04Omer van Kloeten
 
Computational Framework for Generating Visual Summaries of Topical Clusters i...
Computational Framework for Generating Visual Summaries of Topical Clusters i...Computational Framework for Generating Visual Summaries of Topical Clusters i...
Computational Framework for Generating Visual Summaries of Topical Clusters i...Sebastian Alfers
 
Hooking up Semantic MediaWiki with external tools via SPARQL
Hooking up Semantic MediaWiki with external tools via SPARQLHooking up Semantic MediaWiki with external tools via SPARQL
Hooking up Semantic MediaWiki with external tools via SPARQLSamuel Lampa
 
2016 WordCamp Pittsburgh - Let's Write a Plugin
2016 WordCamp Pittsburgh - Let's Write a Plugin2016 WordCamp Pittsburgh - Let's Write a Plugin
2016 WordCamp Pittsburgh - Let's Write a PluginBrian Layman
 
YQL - Christian Heilmann Open Hack London presentation
YQL - Christian Heilmann Open Hack London presentationYQL - Christian Heilmann Open Hack London presentation
YQL - Christian Heilmann Open Hack London presentationKorben00
 
What’s New in Rails 5.0?
What’s New in Rails 5.0?What’s New in Rails 5.0?
What’s New in Rails 5.0?Unboxed
 
With Great Nerdery Comes Great Responsibility
With Great Nerdery Comes Great Responsibility With Great Nerdery Comes Great Responsibility
With Great Nerdery Comes Great Responsibility John Anderson
 
For a Social Local and Mobile Drupal
For a Social Local and Mobile DrupalFor a Social Local and Mobile Drupal
For a Social Local and Mobile DrupalAdyax
 
How to analyze your codebase with Exakat using Docker - Longhorn PHP
How to analyze your codebase with Exakat using Docker - Longhorn PHPHow to analyze your codebase with Exakat using Docker - Longhorn PHP
How to analyze your codebase with Exakat using Docker - Longhorn PHPDana Luther
 
From Android NDK To AOSP
From Android NDK To AOSPFrom Android NDK To AOSP
From Android NDK To AOSPMin-Yih Hsu
 
Headless Drupal
Headless DrupalHeadless Drupal
Headless Drupaldrubb
 
Random Thoughts on Paper Implementations [KAIST 2018]
Random Thoughts on Paper Implementations [KAIST 2018]Random Thoughts on Paper Implementations [KAIST 2018]
Random Thoughts on Paper Implementations [KAIST 2018]Taehoon Kim
 
Batch import of large RDF datasets into Semantic MediaWiki
Batch import of large RDF datasets into Semantic MediaWikiBatch import of large RDF datasets into Semantic MediaWiki
Batch import of large RDF datasets into Semantic MediaWikiSamuel Lampa
 
3.15.17 DSpace: How to Contribute Webinar Slides
3.15.17 DSpace: How to Contribute Webinar Slides3.15.17 DSpace: How to Contribute Webinar Slides
3.15.17 DSpace: How to Contribute Webinar SlidesDuraSpace
 
Android Course - Lesson6
 Android Course - Lesson6 Android Course - Lesson6
Android Course - Lesson6Callum Taylor
 
Debugging Effectively - ConFoo Montreal 2019
Debugging Effectively - ConFoo Montreal 2019Debugging Effectively - ConFoo Montreal 2019
Debugging Effectively - ConFoo Montreal 2019Colin O'Dell
 
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVMQCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVMPeter Pilgrim
 

Similar to React 16: Error Handling (20)

pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)pull requests I sent to scala/scala (ny-scala 2019)
pull requests I sent to scala/scala (ny-scala 2019)
 
Power Up Your Build - Omer van Kloeten @ Wix 2018-04
Power Up Your Build - Omer van Kloeten @ Wix 2018-04Power Up Your Build - Omer van Kloeten @ Wix 2018-04
Power Up Your Build - Omer van Kloeten @ Wix 2018-04
 
Computational Framework for Generating Visual Summaries of Topical Clusters i...
Computational Framework for Generating Visual Summaries of Topical Clusters i...Computational Framework for Generating Visual Summaries of Topical Clusters i...
Computational Framework for Generating Visual Summaries of Topical Clusters i...
 
Versions
VersionsVersions
Versions
 
Hooking up Semantic MediaWiki with external tools via SPARQL
Hooking up Semantic MediaWiki with external tools via SPARQLHooking up Semantic MediaWiki with external tools via SPARQL
Hooking up Semantic MediaWiki with external tools via SPARQL
 
2016 WordCamp Pittsburgh - Let's Write a Plugin
2016 WordCamp Pittsburgh - Let's Write a Plugin2016 WordCamp Pittsburgh - Let's Write a Plugin
2016 WordCamp Pittsburgh - Let's Write a Plugin
 
YQL - Christian Heilmann Open Hack London presentation
YQL - Christian Heilmann Open Hack London presentationYQL - Christian Heilmann Open Hack London presentation
YQL - Christian Heilmann Open Hack London presentation
 
What’s New in Rails 5.0?
What’s New in Rails 5.0?What’s New in Rails 5.0?
What’s New in Rails 5.0?
 
With Great Nerdery Comes Great Responsibility
With Great Nerdery Comes Great Responsibility With Great Nerdery Comes Great Responsibility
With Great Nerdery Comes Great Responsibility
 
For a Social Local and Mobile Drupal
For a Social Local and Mobile DrupalFor a Social Local and Mobile Drupal
For a Social Local and Mobile Drupal
 
How to analyze your codebase with Exakat using Docker - Longhorn PHP
How to analyze your codebase with Exakat using Docker - Longhorn PHPHow to analyze your codebase with Exakat using Docker - Longhorn PHP
How to analyze your codebase with Exakat using Docker - Longhorn PHP
 
From Android NDK To AOSP
From Android NDK To AOSPFrom Android NDK To AOSP
From Android NDK To AOSP
 
Headless Drupal
Headless DrupalHeadless Drupal
Headless Drupal
 
Random Thoughts on Paper Implementations [KAIST 2018]
Random Thoughts on Paper Implementations [KAIST 2018]Random Thoughts on Paper Implementations [KAIST 2018]
Random Thoughts on Paper Implementations [KAIST 2018]
 
Batch import of large RDF datasets into Semantic MediaWiki
Batch import of large RDF datasets into Semantic MediaWikiBatch import of large RDF datasets into Semantic MediaWiki
Batch import of large RDF datasets into Semantic MediaWiki
 
3.15.17 DSpace: How to Contribute Webinar Slides
3.15.17 DSpace: How to Contribute Webinar Slides3.15.17 DSpace: How to Contribute Webinar Slides
3.15.17 DSpace: How to Contribute Webinar Slides
 
Android Course - Lesson6
 Android Course - Lesson6 Android Course - Lesson6
Android Course - Lesson6
 
Debugging Effectively - ConFoo Montreal 2019
Debugging Effectively - ConFoo Montreal 2019Debugging Effectively - ConFoo Montreal 2019
Debugging Effectively - ConFoo Montreal 2019
 
Gophers, whales and.. clouds? Oh my!
Gophers, whales and.. clouds? Oh my!Gophers, whales and.. clouds? Oh my!
Gophers, whales and.. clouds? Oh my!
 
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVMQCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
QCon 2015 Scala for the Enterprise: Get FuNkEd Up on the JVM
 

Recently uploaded

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 

Recently uploaded (20)

The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 

React 16: Error Handling

  • 1. React 16: Error Handling
  • 2. David Slone Front-End Engineer @ Stem Twitter @dbslone Github @dbslone
  • 4. REACT 16 It’s finally here…almost
  • 7. What’s New? • Fiber • Error Boundaries https://github.com/facebook/react/issues/10294
  • 8. What’s New? • Fiber • Error Boundaries • Returning arrays from render https://github.com/facebook/react/issues/10294
  • 9. What’s New? • Fiber • Error Boundaries • Returning arrays from render • Lots of other stuff https://github.com/facebook/react/issues/10294
  • 10. What’s New? • Fiber • Error Boundaries • Returning arrays from render • Lots of other stuff https://github.com/facebook/react/issues/10294
  • 12. Fiber • Complete rewrite of the React core https://github.com/acdlite/react-fiber-architecture
  • 13. Fiber • Complete rewrite of the React core • Unfortunately async render isn’t here yet https://github.com/acdlite/react-fiber-architecture
  • 14. Fiber • Complete rewrite of the React core • Unfortunately async render isn’t here yet • https://www.youtube.com/watch?v=Qu_6ItnlDQg https://github.com/acdlite/react-fiber-architecture
  • 16. Inefficient Renders • React uses recursive diff’ing
  • 17. Inefficient Renders // Before render() { return ( <ul> <li>Hollywood</li> <li>Pasadena</li> </ul> ) } // After render() { return ( <ul> <li>Santa Monica</li> <li>Hollywood</li> <li>Pasadena</li> </ul> ) } • React uses recursive diff’ing • Inserting at the beginning of the list means rendering the whole tree again
  • 18. Inefficient Renders // Before render() { return ( <ul> <li>Hollywood</li> <li>Pasadena</li> </ul> ) } // After render() { return ( <ul> <li>Santa Monica</li> <li>Hollywood</li> <li>Pasadena</li> </ul> ) } • React uses recursive diff’ing • Inserting at the beginning of the list means rendering the whole tree again • Best algorithms have a time complexity O(n3)
  • 19. Inefficient Renders // Before render() { return ( <ul> <li>Hollywood</li> <li>Pasadena</li> </ul> ) } // After render() { return ( <ul> <li>Santa Monica</li> <li>Hollywood</li> <li>Pasadena</li> </ul> ) } • React uses recursive diff’ing • Inserting at the beginning of the list means rendering the whole tree again • Best algorithms have a time complexity O(n3) • 1000 elements === 1billion comparisons
  • 21. The Solution? • Heuristics - using shortcuts today to solve the problems of tomorrow https://facebook.github.io/react/docs/reconciliation.html
  • 22. The Solution? // Before render() { return ( <ul> <li key="Hollywood">Hollywood</li> <li key="Pasadena">Pasadena</li> </ul> ) } // After render() { return ( <ul> <li key="Santa Monica">Santa Monica</li> <li key="Hollywood">Hollywood</li> <li key="Pasadena">Pasadena</li> </ul> ) } • Heuristics - using shortcuts today to solve the problems of tomorrow • Using “key” allows React to match children in the original tree with children in the subsequent tree https://facebook.github.io/react/docs/reconciliation.html
  • 23. The Solution? // Before render() { return ( <ul> <li key="Hollywood">Hollywood</li> <li key="Pasadena">Pasadena</li> </ul> ) } // After render() { return ( <ul> <li key="Santa Monica">Santa Monica</li> <li key="Hollywood">Hollywood</li> <li key="Pasadena">Pasadena</li> </ul> ) } • Heuristics - using shortcuts today to solve the problems of tomorrow • Using “key” allows React to match children in the original tree with children in the subsequent tree • Keys only need to be unique to siblings not the global scope https://facebook.github.io/react/docs/reconciliation.html
  • 24. How is Fiber Different?
  • 25. How is Fiber Different? • A fiber is a JavaScript object that contains information about a component, its input, and its output.
  • 26. How is Fiber Different? • A fiber is a JavaScript object that contains information about a component, its input, and its output. • Allows delaying the render of components by using a priority system
  • 28. Returning arrays render() { return ( <div>Studio City</div> <div>Century City</div> ) }
  • 29. Returning arrays render() { return this.props.item.map((item) => ( <li>{item}</li> )) }
  • 30. Error Handling class ErrorBoundary extends React.Component { constructor(props) { super(props); this.state = { hasError: false }; } componentDidCatch(error, info) { // Display fallback UI this.setState({ hasError: true }); // You can also log the error to an error reporting service logErrorToMyService(error, info); } render() { if (this.state.hasError) { // You can render any custom fallback UI return <h1>Something went wrong.</h1>; } return this.props.children; } }
  • 31. TIME FOR A DEMO