Skip to main content

Recoil

Recoil 是一個 Meta opensouce team 出的 React 狀態管理庫。基於 React 原生的狀態管理,並改善原本一些限制。

沒有 Recoil 的時候

當需要管理一些隔很遠的 state 的時候,用來建立一個更高維度的共享。

兩個隔很遠的共用 state Component 兩個隔很遠得共用 state Component

如果用 Context 搭配 Provider 管理,會遇到第一個問題是會有很多 Provider with-lots-of-provider 第二個問題是如果需要增加,會需要 React 進行整個 unmount 和 remount provider-insert

使用 Recoil 管理

Recoil 是在一個獨立在 React tree 之外的另一個維度中,建立一些可以對應到共享 state 的東西。 recoil-concept

這些東西稱為 Atoms。 atoms

資料來源

动机 | Recoil
Recoil: State Management for Today's React - Dave McCabe aka @mcc_abe at @ReactEurope 2020 - YouTube