Files
react/components/checkbox/checkbox-context.ts
2020-03-19 01:15:58 +08:00

20 lines
472 B
TypeScript

import React from 'react'
export interface CheckboxConfig {
updateState: (value: string, checked: boolean) => void
disabledAll: boolean
values: string[]
inGroup: boolean
}
const defaultContext = {
disabledAll: false,
updateState: () => {},
inGroup: false,
values: [],
}
export const CheckboxContext = React.createContext<CheckboxConfig>(defaultContext)
export const useCheckbox = (): CheckboxConfig => React.useContext<CheckboxConfig>(CheckboxContext)