🧪 test(context): 新增shopping购物模块的context
This commit is contained in:
@@ -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
|
||||
}
|
||||
Reference in New Issue
Block a user