Skip to main content

useGotoRecoilSnapshot(snapshot)

This hook returns a callback which takes a Snapshot as a parameter and will update the current <RecoilRoot> state to match this atom state.

function useGotoRecoilSnapshot(): Snapshot => void

Transaction Example​

Important Note: This example is not efficient because it will subscribe the component to re-render for all state changes.

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>;
}

Time Travel Example​

See the Time Travel Example