mirror of
https://github.com/gromlab-ru/slm-design.git
synced 2026-08-22 07:30:16 +03:00
20 lines
433 B
TypeScript
20 lines
433 B
TypeScript
|
|
'use client'
|
|||
|
|
|
|||
|
|
import { useContext } from 'react'
|
|||
|
|
|
|||
|
|
import { CartContext } from '../cart.context'
|
|||
|
|
import type { CartContextValue } from '../types/cart.type'
|
|||
|
|
|
|||
|
|
/**
|
|||
|
|
* Возвращает application-scoped API корзины.
|
|||
|
|
*/
|
|||
|
|
export const useCart = (): CartContextValue => {
|
|||
|
|
const context = useContext(CartContext)
|
|||
|
|
|
|||
|
|
if (context === null) {
|
|||
|
|
throw new Error('useCart must be used inside CartProvider')
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return context
|
|||
|
|
}
|