このページ
useGotoRecoilSnapshot(snapshot)
function useGotoRecoilSnapshot(): Snapshot => void
コピー
トランザクションの例
function TransactionButton(): React.Node {
const snapshot = useRecoilSnapshot(); // Subscribe to all state changes
const modifiedSnapshot = snapshot.map(({set}) => {
set(atomA, x => x + 1);
set(atomB, x => x * 2);
});
const gotoSnapshot = useGotoRecoilSnapshot();
return <button onClick={() => gotoSnapshot(modifiedSnapshot)}>Perform Transaction</button>;
}
重要事項:すべての状態変更でコンポーネントが再レンダリングをサブスクライブするため、この例は効率的ではありません。
タイムトラベル例