根据文档, https://recoiljs.org/docs/api-reference/core/RecoilRoot
<RecoilRoot>接受 props 作为initializeState?: (MutableSnapshot => void)签名。
能够初始化反冲状态,所以我想使用这个道具,但我不明白如何制作MutableSnapshot对象。
import {RecoilRoot} from 'recoil';
function AppRoot() {
return (
<RecoilRoot initializeState={/* How to setup arguments here? */} >
<ComponentThatUsesRecoil />
</RecoilRoot>
);
}
Run Code Online (Sandbox Code Playgroud)
另一方面,虽然Snapshot更容易获得useRecoilSnapshot()。