mirror of
https://github.com/zhigang1992/react.git
synced 2026-02-10 22:45:11 +08:00
23 lines
479 B
TypeScript
23 lines
479 B
TypeScript
import React from 'react'
|
|
|
|
export interface FieldItem {
|
|
value: string
|
|
label: string
|
|
}
|
|
|
|
export interface FieldsetConfig {
|
|
register: (item: FieldItem) => void
|
|
currentValue: string
|
|
inGroup: boolean
|
|
}
|
|
|
|
const defaultContext = {
|
|
inGroup: false,
|
|
currentValue: '',
|
|
register: () => {},
|
|
}
|
|
|
|
export const FieldsetContext = React.createContext<FieldsetConfig>(defaultContext)
|
|
|
|
export const useFieldset = (): FieldsetConfig => React.useContext<FieldsetConfig>(FieldsetContext)
|