Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function CartButton({ moltinText, moltinShowTotal }) {
const { count, subTotal } = useStore(({ cart }) => cart)
const {
initialize,
modal: { goToCart }
} = useActions(actions => actions)
const [cartId, setCartId] = useLocalStorage('mcart', createCartIdentifier())
// const [customerToken, setCustomerToken] = useLocalStorage('mtoken', null)
// const [customerId, setCustomerId] = useLocalStorage('mcustomer', null)
const btnSuffix =
subTotal || count
? ` (${moltinShowTotal ? subTotal : pluralize(count, 'item')})`
: null
useEffect(() => {
// initialize({ cartId, customerToken, customerId })
actionImp: Action;
thunkImp: Thunk;
};
}
let dispatch = useStoreDispatch();
dispatch({ type: 'FOO' });
let useStoreResult = useStoreState((state: State) => state.stateNumber);
useStoreResult + 1;
let useActionResult = useStoreActions(
(actions: Actions) => actions.actionImp,
);
useActionResult(1);
let store = useStore();
store.getState().stateString + 'world';
const typedHooks = createTypedHooks();
useStoreResult = typedHooks.useStoreState(state => state.stateNumber);
useStoreResult + 1;
useActionResult = typedHooks.useStoreActions(actions => actions.actionImp);
useActionResult(1);
dispatch = typedHooks.useStoreDispatch();
dispatch({
type: 'FOO',
});
store = typedHooks.useStore();
store.getState().stateString + 'world';
let actionNoPayload = typedHooks.useStoreActions(
function MyComponent() {
const token = useStore((state: State) => state.user.token);
const { login } = useActions((dispatch: Actions) => ({
login: dispatch.user.login,
}));
const { addTodo } = useActions((actions: Actions) => ({
addTodo: actions.todos.addTodo,
}));
addTodo('Install easy peasy');
const dispatch = useDispatch();
dispatch({
type: 'ADD_FOO',
payload: 'bar',
});
return (
<button> login({ username: 'foo', password: 'bar' })}>
{token || 'Log in'}
</button>
function Checkout({ stripe }) {
const [initialValues, setInitialValues] = useState({
billingIsShipping: true
})
const [paid, setPaid] = useState(false)
const [order, setOrder] = useState(null)
const { route } = useStore(({ modal }) => modal)
const { id: cartId, subTotal } = useStore(({ cart }) => cart)
const { createOrder, payForOrder, setDirty } = useActions(
({ checkout }) => checkout
)
const { goToBilling, goToShipping } = useActions(({ modal }) => modal)
const { deleteCart } = useActions(({ cart }) => cart)
function validate(values) {
if (route === 'shipping') {
return shippingValidation(values)
} else {
return billingValidation(values)
}
}
async function onSubmit(values) {
export default function Modal({ stripeKey }) {
const { open, route } = useStore(({ modal }) => modal)
const { closeModal } = useActions(({ modal }) => modal)
const [stripeLoaded, stripeError] = useScript('https://js.stripe.com/v3')
const ref = useRef()
useOnClickOutside(ref, closeModal, open)
if (stripeError) {
console.error(stripeError)
return null
}
if (stripeLoaded && !stripeError) {
return (
export default function Cart() {
const { isEmpty, cartItems, promotionItems, subTotal, count } = useStore(
({ cart }) => cart
)
const { goToShipping } = useActions(({ modal }) => modal)
return (
Your shopping cart
{isEmpty ? (
Your cart is empty
) : (
export default function Header({ route }) {
const { closeModal, goToCart, goToShipping } = useActions(
({ modal }) => modal
)
const { dirty, completed } = useStore(({ checkout }) => checkout)
const { loggedIn } = useStore(({ user }) => user)
const handleClick = async () => {
switch (route) {
case 'billing':
if (completed) {
return closeModal()
}
return goToShipping()
case 'shipping': {
if (!completed && dirty) {
const proceed = confirm(
'Are you sure you want to abandon your checkout?'
)
export const useAuth = () => {
const auth = useStore(state => state.auth);
const cachedAuth = JSON.parse(localStorage.getItem('auth')) || {
auth: initialState
};
return {
auth,
cachedAuth
};
};