SlideShare a Scribd company logo
React tips
for everyone
by Mislav Mandaric, 2017-03-30
Contents
• State
• Rerender
• ES2016+
• Composition and Higher Order Components (HOC)
State
• Update should not be done directly
• this.state.key = ‘value’;
• this.setState({ key: ‘value’ });
• Updates are merged
• // current state { key1: ‘value1’, key2: ‘value2’ }
• this.setState({ key1: ‘new value1’, key2: this.state.key2 });
• this.setState({ key1: ‘new value1’ });
• Updates can be async
• this.setState({ key: [...this.state.key,
this.props.newKey] });
• this.setState((prevState, props) => ({ key:
[...prevState.key, props.newKey }));
Rerender
• Reconciliation algorithm
• If node type is different, tear the whole subtree down
• DOM nodes are destroyed
• Component nodes are unmounted
• Create new subtree
• If node type is the same, update its data
• DOM nodes attributes are updated
• Component nodes props are updated
• Rerender current node
Rerender
• Rerender algorithm
• Depends on shouldComponentUpdate method
• If component should not be updated, whole subtree will not be
updated
• Helpful constructs
• PureComponent class with immutable state
ES2016+
• Object spread and rest operators (Stage 3)
• const obj1 = { k1: 1, k2: 2 };
• const obj2 = { k3: 3, k4: 4 };
• const newObj = Object.assign({}, obj1, obj2, { k5: 5 });
• const newObj = {...obj1, ...obj2, k5: 5 };
• const { k1, k2, ...rest } = newObj;
• // rest = { k3: 3, k4: 4, k5: 5 };
• Property initializer syntax (Stage 2)
• this.function = this.function.bind(this);
function () { … }
• this.function = () => { … }
Composition and HOCs
• Extending components functionality without inheritance
• Composition
• Special component renders generic component, with predefined
props and children
• HOCs
• Function accepts component and creates new one with
additional functionality
• Apply this function when need to create new component
Thank you! Questions?
Demo code available at
https://github.com/axilis/chch-react

More Related Content

PDF
React js use contexts and useContext hook
PPTX
mediator
PDF
Understanding react hooks
PPTX
Async Web QA
DOCX
บทที่3
PPTX
SQLCLR Tips & Trics
React js use contexts and useContext hook
mediator
Understanding react hooks
Async Web QA
บทที่3
SQLCLR Tips & Trics

What's hot (18)

PPTX
React-JS Component Life-cycle Methods
PDF
React Internals
PPTX
React hooks
PDF
Martin Anderson - threads v actors
PDF
React new features and intro to Hooks
PDF
[D2 COMMUNITY] ECMAScript 2015 S67 seminar - 2. functions
PDF
RxJava on Android
PPTX
React hooks
PPTX
No More Deadlocks; Asynchronous Programming in .NET
PPTX
Asynchronous programming
PPTX
Mule esb object_to_jackson_json
PDF
Asynchronous JavaScript Programming with Callbacks & Promises
PDF
My Gentle Introduction to RxJS
ODP
Introduction of Object Oriented JavaScript
PPTX
Introduction to React for jQuery Developers
PDF
Intro to RxJava/RxAndroid - GDG Munich Android
PDF
Introduction to Unit Testing (Part 1 of 2)
PDF
Angular & RXJS: examples and use cases
React-JS Component Life-cycle Methods
React Internals
React hooks
Martin Anderson - threads v actors
React new features and intro to Hooks
[D2 COMMUNITY] ECMAScript 2015 S67 seminar - 2. functions
RxJava on Android
React hooks
No More Deadlocks; Asynchronous Programming in .NET
Asynchronous programming
Mule esb object_to_jackson_json
Asynchronous JavaScript Programming with Callbacks & Promises
My Gentle Introduction to RxJS
Introduction of Object Oriented JavaScript
Introduction to React for jQuery Developers
Intro to RxJava/RxAndroid - GDG Munich Android
Introduction to Unit Testing (Part 1 of 2)
Angular & RXJS: examples and use cases
Ad

Similar to React tips (20)

PDF
Evan Schultz - Angular Summit - 2016
PDF
What's new in Cassandra 2.0
PPTX
React JS Workings Exercises Extra Classes
PDF
JavaScript in 2016
PPTX
JavaScript in 2016 (Codemotion Rome)
PDF
Introduction to-mongo db-execution-plan-optimizer-final
PDF
Introduction to Mongodb execution plan and optimizer
PPTX
Interface result set
PPTX
Easy mock
PPT
PPTX
Best Practices in Qt Quick/QML - Part I
 
PPTX
Angular2 for Beginners
PDF
COScheduler
PPT
GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay
PDF
COScheduler In Depth
PDF
InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)
PPTX
How Data Flow analysis works in a static code analyzer
PDF
TOOD: Task-aligned One-stage Object Detection
PPTX
Java script advance-auroskills (2)
PDF
React Development with the MERN Stack
Evan Schultz - Angular Summit - 2016
What's new in Cassandra 2.0
React JS Workings Exercises Extra Classes
JavaScript in 2016
JavaScript in 2016 (Codemotion Rome)
Introduction to-mongo db-execution-plan-optimizer-final
Introduction to Mongodb execution plan and optimizer
Interface result set
Easy mock
Best Practices in Qt Quick/QML - Part I
 
Angular2 for Beginners
COScheduler
GDC 2010 - A Dynamic Component Architecture for High Performance Gameplay
COScheduler In Depth
InterConnect 2016, OpenJPA and EclipseLink Usage Scenarios (PEJ-5303)
How Data Flow analysis works in a static code analyzer
TOOD: Task-aligned One-stage Object Detection
Java script advance-auroskills (2)
React Development with the MERN Stack
Ad

More from Axilis (20)

PDF
Web App Security for Devs
PDF
Configuring SSL on NGNINX and less tricky servers
PPTX
Journey to Microservice architecture via Amazon Lambda
PPTX
Should you react?
PPTX
Sweet ES2015 (ES6) Taste
PPTX
NuGet Must Haves for LINQ
PPTX
Quick introduction to zeplin
PPTX
Diving into Node with Express and Mongo
PDF
Node in Real Time - The Beginning
PPTX
Road to Dynamic LINQ - Part 2
PPTX
Road to Dynamic LINQ Part 1
PPTX
.NET Core - Sve što trebate znati
PPTX
Angular Translate
PPTX
NPM, Bower and Gulp Kickstart in Visual Studio
PPTX
Dive Into Swift
PPTX
Python Tools for Visual Studio
PPTX
Python Tools for Visual Studio
PPTX
Wireframing
PPTX
Angular 2.0: Getting ready
PPTX
Angular JS deep dive
Web App Security for Devs
Configuring SSL on NGNINX and less tricky servers
Journey to Microservice architecture via Amazon Lambda
Should you react?
Sweet ES2015 (ES6) Taste
NuGet Must Haves for LINQ
Quick introduction to zeplin
Diving into Node with Express and Mongo
Node in Real Time - The Beginning
Road to Dynamic LINQ - Part 2
Road to Dynamic LINQ Part 1
.NET Core - Sve što trebate znati
Angular Translate
NPM, Bower and Gulp Kickstart in Visual Studio
Dive Into Swift
Python Tools for Visual Studio
Python Tools for Visual Studio
Wireframing
Angular 2.0: Getting ready
Angular JS deep dive

Recently uploaded (20)

PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
Cost to Outsource Software Development in 2025
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PDF
Digital Systems & Binary Numbers (comprehensive )
PDF
iTop VPN Crack Latest Version Full Key 2025
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
PDF
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
assetexplorer- product-overview - presentation
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Salesforce Agentforce AI Implementation.pdf
PPTX
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
PDF
Website Design Services for Small Businesses.pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 41
wealthsignaloriginal-com-DS-text-... (1).pdf
Autodesk AutoCAD Crack Free Download 2025
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Cost to Outsource Software Development in 2025
Navsoft: AI-Powered Business Solutions & Custom Software Development
Oracle Fusion HCM Cloud Demo for Beginners
Digital Systems & Binary Numbers (comprehensive )
iTop VPN Crack Latest Version Full Key 2025
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
How AI/LLM recommend to you ? GDG meetup 16 Aug by Fariman Guliev
CapCut Video Editor 6.8.1 Crack for PC Latest Download (Fully Activated) 2025
Adobe Illustrator 28.6 Crack My Vision of Vector Design
assetexplorer- product-overview - presentation
Operating system designcfffgfgggggggvggggggggg
Design an Analysis of Algorithms II-SECS-1021-03
CHAPTER 2 - PM Management and IT Context
Salesforce Agentforce AI Implementation.pdf
WiFi Honeypot Detecscfddssdffsedfseztor.pptx
Website Design Services for Small Businesses.pdf

React tips

  • 1. React tips for everyone by Mislav Mandaric, 2017-03-30
  • 2. Contents • State • Rerender • ES2016+ • Composition and Higher Order Components (HOC)
  • 3. State • Update should not be done directly • this.state.key = ‘value’; • this.setState({ key: ‘value’ }); • Updates are merged • // current state { key1: ‘value1’, key2: ‘value2’ } • this.setState({ key1: ‘new value1’, key2: this.state.key2 }); • this.setState({ key1: ‘new value1’ }); • Updates can be async • this.setState({ key: [...this.state.key, this.props.newKey] }); • this.setState((prevState, props) => ({ key: [...prevState.key, props.newKey }));
  • 4. Rerender • Reconciliation algorithm • If node type is different, tear the whole subtree down • DOM nodes are destroyed • Component nodes are unmounted • Create new subtree • If node type is the same, update its data • DOM nodes attributes are updated • Component nodes props are updated • Rerender current node
  • 5. Rerender • Rerender algorithm • Depends on shouldComponentUpdate method • If component should not be updated, whole subtree will not be updated • Helpful constructs • PureComponent class with immutable state
  • 6. ES2016+ • Object spread and rest operators (Stage 3) • const obj1 = { k1: 1, k2: 2 }; • const obj2 = { k3: 3, k4: 4 }; • const newObj = Object.assign({}, obj1, obj2, { k5: 5 }); • const newObj = {...obj1, ...obj2, k5: 5 }; • const { k1, k2, ...rest } = newObj; • // rest = { k3: 3, k4: 4, k5: 5 }; • Property initializer syntax (Stage 2) • this.function = this.function.bind(this); function () { … } • this.function = () => { … }
  • 7. Composition and HOCs • Extending components functionality without inheritance • Composition • Special component renders generic component, with predefined props and children • HOCs • Function accepts component and creates new one with additional functionality • Apply this function when need to create new component
  • 8. Thank you! Questions? Demo code available at https://github.com/axilis/chch-react