SZ


Использование


Recoil


в React и React Native
Sergii Zhuravel
Key facts
• Industry:


Telecom, IoT, Automotive, CRM


• Location:


Kyiv, UKR


• Position:


Lead Software Engineer


• Company


Absio
Fan of JavaScript and JS frameworks. I like table tennis,
fishing and traveling
Plan to review
•Проблема управления стейтом в React


•Популярные решения для управления стейтом


•Основы Recoil


•Что такое ADHD и почему мы используем Recoil


•Как мы используем Recoil в мобильном приложении


•Тестирование Recoil атомов и селекторов
State management problem in React
❑Различные типы стейта


❑Много библиотек и подходов


❑Различные платформы(React, React native)
Types of state
1. Component’s (local) State


2. Components shared state


3. App’s (global) state


4. UI state


5. Cache (Redux, GraphQL cache)
Redux in 2021?
Why React projects still use Redux
What about Recoil?
What about Recoil?
Recoil – Advantages
1.Minimal and Reactish
2.Easy Learning Curve (just Atoms and Selectors)
3.Boilerplate-free API
4.Distributed and incremental state definition


5.Supports React Suspense
What is Recoil?
Atoms + Selectors + hooks + utilities
Recoil – Atoms
Atoms contain the source of truth for our
application state.
Recoil – Selectors
A selector represents a piece of derived
state. You can think of derived state as the
output of passing state to a pure function
that modifies the given state in some way.
What about ADHD?
What about ADHD?
React App – Login View State
Path:
• srcstorestatelogin-view.state.ts
React App – Login View
Path: srcviewsauthloginlogin.view.tsx
React App – RecoilRoot
Path:
srcindex.tsx
React App – Observing events
Path:
srcindex.tsx
React App – Observing events
Path:
srcindex.tsx
React App – Observing events (topics)
Path:
srcindex.tsx
React App – Selectors
Path:
srcindex.tsx
React Native App – Login View State
Path:
• srcstorestatelogin-view.state.ts
React Native App – Navigation
Path: srcviewsauthloginlogin.view.tsx
React Native App – RecoilRoot
Path:
srcApp.tsx
Testing Recoil
Use RecoilRoot in your tests
Testing Recoil
Use ReoilObserver to track atom


and/or selector change
Testing Recoil – RecoilObserver
Use ReoilObserver to track atom


and/or selector change
Testing Recoil - snapshot_UNSTABLE()
Use ReoilObserver to track atom


and/or selector change
Summary:
• Recoil is still experimental, but it’s used in production in many projects


• Recoil can be used in React and React native


• Recoil is very easy to test (within React context and outside)


• Have you tried Recoil already?
Links:
• https://recoiljs.org
• https://recoiljs.org/resources/
• https://adhdamerica.org/
• https://github.com/sergii-zhuravel
Thank you!


Sergii Zhuravel


https://twitter.com/SZhuravel

Использование Recoil в React и React Native приложениях | Odessa Frontend Meetup #19