SlideShare a Scribd company logo
Recoil
Kraków, 2020-08-25
Mateusz Bryła
Team Lead
mateusz.bryla@codete.com
menti.com
31 33 67 2
Agenda
● Meet the audience ;)
● Where we are with state management?
● Let’s listen to the story of ........................ - the Project Owner
● Recoil basics
● Live demo ;)
● Summary
● Further reading
● Q&A
State of the art of the management of the state
Flexibility,
Possibilities
Effort,
Overhead,
Learning curve
●
Redux
●
useState + props
●
React Context
●
Redux + Redux Toolkit
●
MobX
CC BY-ND 2.0 by Pierre Reveille
Let’s build a map app
App base
export const App = () => {
return (
<>
<Sidebar />
<Canvas />
</>
);
};
Cool feature: user draggable markers!
Markers support
export const App = () => {
const [markersIds, setMarkersIds] = useState([]);
return (
<>
<SideBar setMarkerIds={setMarkersIds} />
<Canvas>
{markersIds.map(id => <MapMarker id={id} key={id} />)}
</Canvas>
</>
);
};
export const MapMarker = ({ id }) => {
const [state, setState] = useState(createInitialMarkerState());
return createCanvasMarker(state, setState);
}
Cool feature #2: inputs and statistics!
Problem
What would be the React way?
What would be the ideal way?
Meet Recoil!
Where?
https://github.com/facebookexperimental/Recoil
(mind the “experimental” - it’s only v0.10!)
In numbers?
● created 2020-05-04
● 9k stars, ~400 forks, 40 contributors
How?
● yarn add recoil
● wrap your app with <RecoilProvider>
Why?
You’ll see in a minute ;)
2020-08-25, https://www.npmtrends.com/recoil
The Recoil way
Local state
export const SimpleMapMarker = () => {
const [latlng, setLatlng] = useState([0, 0]);
return <CanvasDraggableMarker latlng={latlng} setLatlng={setLatlng} />
}
export const SimpleMarkerInputFields = () => {
const [latlng, setLatlng] = useState([0, 0]);
return <LatitudeLongitudeNumberInputs latlng={latlng} setLatlng={setLatlng} />
}
State shared through Recoil atom
import { useRecoilState } from 'recoil';
import { markerPosition } from './MarkerState';
export const SimpleMapMarker = () => {
const [latlng, setLatlng] = useRecoilState(markerPosition);
return <CanvasDraggableMarker latlng={latlng} setLatlng={setLatlng} />
}
import { useRecoilState } from 'recoil';
import { markerPosition } from './MarkerState';
export const SimpleMarkerInputFields = () => {
const [latlng, setLatlng] = useRecoilState(markerPosition);
return <LatitudeLongitudeNumberInputs latlng={latlng} setLatlng={setLatlng} />
}
Recoil Atom
export const markerPosition = atom({
key: 'markerPosition',
default: [0, 0],
});
Recoil Atom (for real)
export const markerPosition = atom({
key: 'markerPosition',
default: [0, 0],
});
export const markerWithId = memoize((id) => atom({
key: `marker-${id}`,
default: [0, 0],
}));
Recoil Atom (for real)
export const markerWithId = memoize((id) => atom({
key: `marker-${id}`,
default: [0, 0],
}));
export const MapMarker = ({ id }) => {
const [state, setState] = useState(createInitialMarkerState());
return createCanvasMarker(state, setState);
}
export const MapMarker = ({ id }) => {
const [state, setState] = useRecoilState(markerWithId(id));
return createCanvasMarker(state, setState);
}
Cool feature #3: …?
Cool feature #3: GEOFENCING!
Cool feature #3: …?
Derived values - Recoil selector
export const geofence = selector({
key: 'geofence',
get: ({ get }) => {
const selectedMarkersIds = get(selectionAtom);
const selectedItems = selectedMarkersIds.map((id) => get(markerWithId(id)));
return createGeofence(selectedItems);
},
});
Async selector? No problem ;)
export const geofence = selector({
key: 'geofence',
get: ({ get }) => {
const selectedMarkersIds = get(selectionAtom);
const selectedItems = selectedMarkersIds.map((id) => get(markerWithId(id)));
return new Promise(createGeofence(selectedItems));
},
});
Cool feature #4: Persistence
https://my-amazing-map.com/?markers=[...],geofence=[...]
State observation
useRecoilTransactionObserver_UNSTABLE(({
snapshot,
}) => {
persist(snapshot.getLoadable(someAtom));
});
Recoil core concepts - summary
● Flexible shared state
● Derived data and queries
● App-wide state observation
● (built in asynchronous data handling)
● (built in React concurrent ready)
Demo time!
Should I bother?
If you…
● Need more than a simple Context can handle
● Don’t like to introduce too much overhead
● Are not scared by the “experimental” keyword…
● … but want to be ready for React Concurrent Mode
… then at least give it a try ;)
For under-the-hood addicts
● Works similar to react-redux
○ <Provider> exposes Redux internal tree structure, connect wraps with HOC
and allows data read (only when necessary) and manipulation
○ <RecoilRoot> exposes Recoil internal Atoms tree structure, hooks allow data
read (only when necessary) and manipulation
● There is more, check it out yourself ;)
For bettime readers
● Introduction to Recoil by its creator - Dave McCabe (@mcc_abe)
https://www.youtube.com/watch?v=_ISAA_Jt9kI
● Official Recoil docs (be aware of “This API is currently under development and will change”)
https://recoiljs.org/docs/introduction/core-concepts
● Recoil source
https://github.com/facebookexperimental/Recoil
● React concurrent mode
https://pl.reactjs.org/docs/concurrent-mode-intro.html
● This presentation
TODO PASTE LINK ;)
Q & A
Thank you!
Mateusz Bryła
Team Lead
@ mateusz.bryla@lingmates.com
Web lingmates.com
LinkedIn mateusz-bryla

More Related Content

What's hot

Cpp
Cpp Cpp
Richard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleRichard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL Module
Axway Appcelerator
 
React. Redux. Real world.
React. Redux. Real world.React. Redux. Real world.
React. Redux. Real world.
Rost Galkin
 
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
Ontico
 
Richard Fridrich: Třesení stromem v JavaScriptu
Richard Fridrich: Třesení stromem v JavaScriptuRichard Fridrich: Třesení stromem v JavaScriptu
Richard Fridrich: Třesení stromem v JavaScriptu
Develcz
 
Qt Item Views In Depth
Qt Item Views In DepthQt Item Views In Depth
Qt Item Views In Depth
Marius Bugge Monsen
 
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyDesign Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
ManageIQ
 
vbscript-reference book
vbscript-reference bookvbscript-reference book
vbscript-reference book
Anand Dhana
 
Advanced JavaScript Concepts
Advanced JavaScript ConceptsAdvanced JavaScript Concepts
Advanced JavaScript Concepts
Naresh Kumar
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
Eyal Vardi
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2
Jeado Ko
 
Javascript: repetita iuvant
Javascript: repetita iuvantJavascript: repetita iuvant
Javascript: repetita iuvant
Luciano Mammino
 
Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)
vitalipe
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
Rick Beerendonk
 
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline codeRajeev Sharan
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013
Laurent_VB
 
Lecture 6 introduction to open gl and glut
Lecture 6   introduction to open gl and glutLecture 6   introduction to open gl and glut
Lecture 6 introduction to open gl and glut
simpleok
 
Angular js performance improvements
Angular js performance improvementsAngular js performance improvements
Angular js performance improvements
Sigmoid
 
[2019] Java에서 Fiber를 이용하여 동시성concurrency 프로그래밍 쉽게 하기
[2019] Java에서 Fiber를 이용하여 동시성concurrency 프로그래밍 쉽게 하기[2019] Java에서 Fiber를 이용하여 동시성concurrency 프로그래밍 쉽게 하기
[2019] Java에서 Fiber를 이용하여 동시성concurrency 프로그래밍 쉽게 하기
NHN FORWARD
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
Eyal Vardi
 

What's hot (20)

Cpp
Cpp Cpp
Cpp
 
Richard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL ModuleRichard Salter: Using the Titanium OpenGL Module
Richard Salter: Using the Titanium OpenGL Module
 
React. Redux. Real world.
React. Redux. Real world.React. Redux. Real world.
React. Redux. Real world.
 
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
Amazing threesome, rrr... React. Redux. Real world / Ростислав Галкин (Babo)
 
Richard Fridrich: Třesení stromem v JavaScriptu
Richard Fridrich: Třesení stromem v JavaScriptuRichard Fridrich: Třesení stromem v JavaScriptu
Richard Fridrich: Třesení stromem v JavaScriptu
 
Qt Item Views In Depth
Qt Item Views In DepthQt Item Views In Depth
Qt Item Views In Depth
 
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin PovolnyDesign Summit - UI Roadmap - Dan Clarizio, Martin Povolny
Design Summit - UI Roadmap - Dan Clarizio, Martin Povolny
 
vbscript-reference book
vbscript-reference bookvbscript-reference book
vbscript-reference book
 
Advanced JavaScript Concepts
Advanced JavaScript ConceptsAdvanced JavaScript Concepts
Advanced JavaScript Concepts
 
Performance Optimization In Angular 2
Performance Optimization In Angular 2Performance Optimization In Angular 2
Performance Optimization In Angular 2
 
Reactive, component 그리고 angular2
Reactive, component 그리고  angular2Reactive, component 그리고  angular2
Reactive, component 그리고 angular2
 
Javascript: repetita iuvant
Javascript: repetita iuvantJavascript: repetita iuvant
Javascript: repetita iuvant
 
Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)Qt Graphics View Framework (Qt Developers Meetup Isreal)
Qt Graphics View Framework (Qt Developers Meetup Isreal)
 
JavaScript 2016 for C# Developers
JavaScript 2016 for C# DevelopersJavaScript 2016 for C# Developers
JavaScript 2016 for C# Developers
 
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline code
 
Developing web-apps like it's 2013
Developing web-apps like it's 2013Developing web-apps like it's 2013
Developing web-apps like it's 2013
 
Lecture 6 introduction to open gl and glut
Lecture 6   introduction to open gl and glutLecture 6   introduction to open gl and glut
Lecture 6 introduction to open gl and glut
 
Angular js performance improvements
Angular js performance improvementsAngular js performance improvements
Angular js performance improvements
 
[2019] Java에서 Fiber를 이용하여 동시성concurrency 프로그래밍 쉽게 하기
[2019] Java에서 Fiber를 이용하여 동시성concurrency 프로그래밍 쉽게 하기[2019] Java에서 Fiber를 이용하여 동시성concurrency 프로그래밍 쉽게 하기
[2019] Java에서 Fiber를 이용하여 동시성concurrency 프로그래밍 쉽게 하기
 
Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)Angular 2 Architecture (Bucharest 26/10/2016)
Angular 2 Architecture (Bucharest 26/10/2016)
 

Similar to Recoil at Codete Webinars #3

Ngrx
NgrxNgrx
Side effects-con-redux
Side effects-con-reduxSide effects-con-redux
Side effects-con-redux
Nicolas Quiceno Benavides
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.js
Josh Staples
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
Babacar NIANG
 
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Igalia
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applications
Evangelia Mitsopoulou
 
Road to react hooks
Road to react hooksRoad to react hooks
Road to react hooks
Younes (omar) Meliani
 
React native tour
React native tourReact native tour
React native tour
Magdiel Duarte
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
Jeado Ko
 
Average- An android project
Average- An android projectAverage- An android project
Average- An android projectIpsit Dash
 
How to separate frontend from a highload python project with no problems - Py...
How to separate frontend from a highload python project with no problems - Py...How to separate frontend from a highload python project with no problems - Py...
How to separate frontend from a highload python project with no problems - Py...
Oleksandr Tarasenko
 
MobileCity:Core Data
MobileCity:Core DataMobileCity:Core Data
MobileCity:Core DataAllan Davis
 
Keeping Track of Moving Things: MapKit and CoreLocation in Depth
Keeping Track of Moving Things: MapKit and CoreLocation in DepthKeeping Track of Moving Things: MapKit and CoreLocation in Depth
Keeping Track of Moving Things: MapKit and CoreLocation in Depth
Geoffrey Goetz
 
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
Techsylvania
 
Google Maps API 101
Google Maps API 101Google Maps API 101
Google Maps API 101
Sebastian Roming
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android Games
Platty Soft
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
Jeremy Grancher
 
Core Location and Map Kit: Bringing Your Own Maps [Voices That Matter: iPhone...
Core Location and Map Kit: Bringing Your Own Maps [Voices That Matter: iPhone...Core Location and Map Kit: Bringing Your Own Maps [Voices That Matter: iPhone...
Core Location and Map Kit: Bringing Your Own Maps [Voices That Matter: iPhone...
Chris Adamson
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
Domenic Denicola
 

Similar to Recoil at Codete Webinars #3 (20)

Ngrx
NgrxNgrx
Ngrx
 
Side effects-con-redux
Side effects-con-reduxSide effects-con-redux
Side effects-con-redux
 
Integrating Angular js & three.js
Integrating Angular js & three.jsIntegrating Angular js & three.js
Integrating Angular js & three.js
 
End to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux SagaEnd to end todo list app with NestJs - Angular - Redux & Redux Saga
End to end todo list app with NestJs - Angular - Redux & Redux Saga
 
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
Standardizing JavaScript Decorators in TC39 (Full Stack Fest 2019)
 
Battle of React State Managers in frontend applications
Battle of React State Managers in frontend applicationsBattle of React State Managers in frontend applications
Battle of React State Managers in frontend applications
 
Road to react hooks
Road to react hooksRoad to react hooks
Road to react hooks
 
React native tour
React native tourReact native tour
React native tour
 
[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법[FEConf Korea 2017]Angular 컴포넌트 대화법
[FEConf Korea 2017]Angular 컴포넌트 대화법
 
Average- An android project
Average- An android projectAverage- An android project
Average- An android project
 
How to separate frontend from a highload python project with no problems - Py...
How to separate frontend from a highload python project with no problems - Py...How to separate frontend from a highload python project with no problems - Py...
How to separate frontend from a highload python project with no problems - Py...
 
MobileCity:Core Data
MobileCity:Core DataMobileCity:Core Data
MobileCity:Core Data
 
Keeping Track of Moving Things: MapKit and CoreLocation in Depth
Keeping Track of Moving Things: MapKit and CoreLocation in DepthKeeping Track of Moving Things: MapKit and CoreLocation in Depth
Keeping Track of Moving Things: MapKit and CoreLocation in Depth
 
Day 1
Day 1Day 1
Day 1
 
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
Cristiano Betta (Betta Works) - Lightweight Libraries with Rollup, Riot and R...
 
Google Maps API 101
Google Maps API 101Google Maps API 101
Google Maps API 101
 
Tools for developing Android Games
 Tools for developing Android Games Tools for developing Android Games
Tools for developing Android Games
 
React Native custom components
React Native custom componentsReact Native custom components
React Native custom components
 
Core Location and Map Kit: Bringing Your Own Maps [Voices That Matter: iPhone...
Core Location and Map Kit: Bringing Your Own Maps [Voices That Matter: iPhone...Core Location and Map Kit: Bringing Your Own Maps [Voices That Matter: iPhone...
Core Location and Map Kit: Bringing Your Own Maps [Voices That Matter: iPhone...
 
The State of JavaScript (2015)
The State of JavaScript (2015)The State of JavaScript (2015)
The State of JavaScript (2015)
 

Recently uploaded

Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
ayushiqss
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Hivelance Technology
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
Cyanic lab
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
Peter Caitens
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Anthony Dahanne
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
varshanayak241
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
Ortus Solutions, Corp
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 

Recently uploaded (20)

Why React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdfWhy React Native as a Strategic Advantage for Startup Innovation.pdf
Why React Native as a Strategic Advantage for Startup Innovation.pdf
 
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
Multiple Your Crypto Portfolio with the Innovative Features of Advanced Crypt...
 
Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024Globus Connect Server Deep Dive - GlobusWorld 2024
Globus Connect Server Deep Dive - GlobusWorld 2024
 
Cyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdfCyaniclab : Software Development Agency Portfolio.pdf
Cyaniclab : Software Development Agency Portfolio.pdf
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
SOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBrokerSOCRadar Research Team: Latest Activities of IntelBroker
SOCRadar Research Team: Latest Activities of IntelBroker
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Advanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should KnowAdvanced Flow Concepts Every Developer Should Know
Advanced Flow Concepts Every Developer Should Know
 
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
Paketo Buildpacks : la meilleure façon de construire des images OCI? DevopsDa...
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
Strategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptxStrategies for Successful Data Migration Tools.pptx
Strategies for Successful Data Migration Tools.pptx
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
Into the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdfInto the Box 2024 - Keynote Day 2 Slides.pdf
Into the Box 2024 - Keynote Day 2 Slides.pdf
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 

Recoil at Codete Webinars #3

  • 1. Recoil Kraków, 2020-08-25 Mateusz Bryła Team Lead mateusz.bryla@codete.com
  • 3. Agenda ● Meet the audience ;) ● Where we are with state management? ● Let’s listen to the story of ........................ - the Project Owner ● Recoil basics ● Live demo ;) ● Summary ● Further reading ● Q&A
  • 4. State of the art of the management of the state Flexibility, Possibilities Effort, Overhead, Learning curve ● Redux ● useState + props ● React Context ● Redux + Redux Toolkit ● MobX
  • 5. CC BY-ND 2.0 by Pierre Reveille
  • 6. Let’s build a map app
  • 7. App base export const App = () => { return ( <> <Sidebar /> <Canvas /> </> ); };
  • 8. Cool feature: user draggable markers!
  • 9. Markers support export const App = () => { const [markersIds, setMarkersIds] = useState([]); return ( <> <SideBar setMarkerIds={setMarkersIds} /> <Canvas> {markersIds.map(id => <MapMarker id={id} key={id} />)} </Canvas> </> ); }; export const MapMarker = ({ id }) => { const [state, setState] = useState(createInitialMarkerState()); return createCanvasMarker(state, setState); }
  • 10. Cool feature #2: inputs and statistics!
  • 12. What would be the React way?
  • 13. What would be the ideal way?
  • 14. Meet Recoil! Where? https://github.com/facebookexperimental/Recoil (mind the “experimental” - it’s only v0.10!) In numbers? ● created 2020-05-04 ● 9k stars, ~400 forks, 40 contributors How? ● yarn add recoil ● wrap your app with <RecoilProvider> Why? You’ll see in a minute ;) 2020-08-25, https://www.npmtrends.com/recoil
  • 16. Local state export const SimpleMapMarker = () => { const [latlng, setLatlng] = useState([0, 0]); return <CanvasDraggableMarker latlng={latlng} setLatlng={setLatlng} /> } export const SimpleMarkerInputFields = () => { const [latlng, setLatlng] = useState([0, 0]); return <LatitudeLongitudeNumberInputs latlng={latlng} setLatlng={setLatlng} /> }
  • 17. State shared through Recoil atom import { useRecoilState } from 'recoil'; import { markerPosition } from './MarkerState'; export const SimpleMapMarker = () => { const [latlng, setLatlng] = useRecoilState(markerPosition); return <CanvasDraggableMarker latlng={latlng} setLatlng={setLatlng} /> } import { useRecoilState } from 'recoil'; import { markerPosition } from './MarkerState'; export const SimpleMarkerInputFields = () => { const [latlng, setLatlng] = useRecoilState(markerPosition); return <LatitudeLongitudeNumberInputs latlng={latlng} setLatlng={setLatlng} /> }
  • 18. Recoil Atom export const markerPosition = atom({ key: 'markerPosition', default: [0, 0], });
  • 19. Recoil Atom (for real) export const markerPosition = atom({ key: 'markerPosition', default: [0, 0], }); export const markerWithId = memoize((id) => atom({ key: `marker-${id}`, default: [0, 0], }));
  • 20. Recoil Atom (for real) export const markerWithId = memoize((id) => atom({ key: `marker-${id}`, default: [0, 0], })); export const MapMarker = ({ id }) => { const [state, setState] = useState(createInitialMarkerState()); return createCanvasMarker(state, setState); } export const MapMarker = ({ id }) => { const [state, setState] = useRecoilState(markerWithId(id)); return createCanvasMarker(state, setState); }
  • 22. Cool feature #3: GEOFENCING!
  • 24. Derived values - Recoil selector export const geofence = selector({ key: 'geofence', get: ({ get }) => { const selectedMarkersIds = get(selectionAtom); const selectedItems = selectedMarkersIds.map((id) => get(markerWithId(id))); return createGeofence(selectedItems); }, });
  • 25. Async selector? No problem ;) export const geofence = selector({ key: 'geofence', get: ({ get }) => { const selectedMarkersIds = get(selectionAtom); const selectedItems = selectedMarkersIds.map((id) => get(markerWithId(id))); return new Promise(createGeofence(selectedItems)); }, });
  • 26. Cool feature #4: Persistence https://my-amazing-map.com/?markers=[...],geofence=[...]
  • 27. State observation useRecoilTransactionObserver_UNSTABLE(({ snapshot, }) => { persist(snapshot.getLoadable(someAtom)); });
  • 28. Recoil core concepts - summary ● Flexible shared state ● Derived data and queries ● App-wide state observation ● (built in asynchronous data handling) ● (built in React concurrent ready)
  • 30. Should I bother? If you… ● Need more than a simple Context can handle ● Don’t like to introduce too much overhead ● Are not scared by the “experimental” keyword… ● … but want to be ready for React Concurrent Mode … then at least give it a try ;)
  • 31. For under-the-hood addicts ● Works similar to react-redux ○ <Provider> exposes Redux internal tree structure, connect wraps with HOC and allows data read (only when necessary) and manipulation ○ <RecoilRoot> exposes Recoil internal Atoms tree structure, hooks allow data read (only when necessary) and manipulation ● There is more, check it out yourself ;)
  • 32. For bettime readers ● Introduction to Recoil by its creator - Dave McCabe (@mcc_abe) https://www.youtube.com/watch?v=_ISAA_Jt9kI ● Official Recoil docs (be aware of “This API is currently under development and will change”) https://recoiljs.org/docs/introduction/core-concepts ● Recoil source https://github.com/facebookexperimental/Recoil ● React concurrent mode https://pl.reactjs.org/docs/concurrent-mode-intro.html ● This presentation TODO PASTE LINK ;)
  • 33. Q & A
  • 34. Thank you! Mateusz Bryła Team Lead @ mateusz.bryla@lingmates.com Web lingmates.com LinkedIn mateusz-bryla