import {atom, selector} from 'recoil';
import {getBasket} from '../API/shoppingBasketAPI';

export const _shoppingBasket = atom({
    key: '_shoppingBasket',
    default: undefined
});

export const shoppingBasket = selector({
    key: 'shoppingBasket',
    get: ({get}) => {
        return get(_shoppingBasket) || getBasket();
    },
    set: ({set}, newValue) => {
        set(_shoppingBasket, newValue);
    }
})
