SlideShare a Scribd company logo
1 of 34
Download to read offline
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

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
 
Declaring friend function with inline code
Declaring friend function with inline codeDeclaring friend function with inline code
Declaring friend function with inline code
Rajeev Sharan
 
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
 

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

Average- An android project
Average- An android projectAverage- An android project
Average- An android project
Ipsit Dash
 
MobileCity:Core Data
MobileCity:Core DataMobileCity:Core Data
MobileCity:Core Data
Allan Davis
 
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
 

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

Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
drm1699
 

Recently uploaded (20)

A Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdfA Deep Dive into Secure Product Development Frameworks.pdf
A Deep Dive into Secure Product Development Frameworks.pdf
 
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
CERVED e Neo4j su una nuvola, migrazione ed evoluzione di un grafo mission cr...
 
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
Abortion Pills For Sale WhatsApp[[+27737758557]] In Birch Acres, Abortion Pil...
 
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
Abortion Clinic In Pretoria ](+27832195400*)[ 🏥 Safe Abortion Pills in Pretor...
 
From Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST APIFrom Theory to Practice: Utilizing SpiraPlan's REST API
From Theory to Practice: Utilizing SpiraPlan's REST API
 
Software Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements EngineeringSoftware Engineering - Introduction + Process Models + Requirements Engineering
Software Engineering - Introduction + Process Models + Requirements Engineering
 
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
Workshop -  Architecting Innovative Graph Applications- GraphSummit MilanWorkshop -  Architecting Innovative Graph Applications- GraphSummit Milan
Workshop - Architecting Innovative Graph Applications- GraphSummit Milan
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
Abortion Pill Prices Germiston ](+27832195400*)[ 🏥 Women's Abortion Clinic in...
 
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
[GeeCON2024] How I learned to stop worrying and love the dark silicon apocalypse
 
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
Navigation in flutter – how to add stack, tab, and drawer navigators to your ...
 
Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024Modern binary build systems - PyCon 2024
Modern binary build systems - PyCon 2024
 
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdfThe Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
The Evolution of Web App Testing_ An Ultimate Guide to Future Trends.pdf
 
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
Abortion Clinic In Polokwane ](+27832195400*)[ 🏥 Safe Abortion Pills in Polok...
 
architecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdfarchitecting-ai-in-the-enterprise-apis-and-applications.pdf
architecting-ai-in-the-enterprise-apis-and-applications.pdf
 
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCAOpenChain Webinar: AboutCode and Beyond - End-to-End SCA
OpenChain Webinar: AboutCode and Beyond - End-to-End SCA
 
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
Abortion Clinic Pretoria ](+27832195400*)[ Abortion Clinic Near Me ● Abortion...
 
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale IbridaUNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
UNI DI NAPOLI FEDERICO II - Il ruolo dei grafi nell'AI Conversazionale Ibrida
 
The Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test AutomationThe Strategic Impact of Buying vs Building in Test Automation
The Strategic Impact of Buying vs Building in Test Automation
 
The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)The mythical technical debt. (Brooke, please, forgive me)
The mythical technical debt. (Brooke, please, forgive me)
 

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