🧪 test(context): 新增shopping购物模块的context

This commit is contained in:
xuan
2022-09-22 19:31:49 +08:00
parent b51c53a73a
commit 553445f111
7 changed files with 198 additions and 52 deletions
+36
View File
@@ -0,0 +1,36 @@
import React from 'react'
import { useContext } from 'react'
/**
* 456: {
* id: 456,
* name: 'asdfasf',
* checked: true
* },
* 457: {
* id: 457,
* name: 'dsfaf654',
* checked: true
* }
*/
export type ColorStore = Record<string, any>
export interface ColorMeta {
id?: number
checked?: boolean
}
export interface ShoppingContextValue {
colorStore: ColorStore
setChangedCheckbox: (color: ColorMeta) => void
}
export const ShoppingContext = React.createContext<ShoppingContextValue | null>(null)
export function useShoppingContext() {
const ctx = useContext(ShoppingContext)
if (!ctx) {
throw new Error('没有获取到shopping context')
}
return ctx
}