Skip to content

Commit

Permalink
feat: export useConfig (#6501)
Browse files Browse the repository at this point in the history
* feat: export useConfig

* chore: test & limit exceed

---------

Co-authored-by: 二货机器人 <[email protected]>
  • Loading branch information
guoyunhe and zombieJ authored Mar 1, 2024
1 parent 8468a08 commit 4a43616
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
5 changes: 3 additions & 2 deletions src/components/config-provider/config-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import zhCN from '../../locales/zh-CN'

type Config = {
locale: Locale
children?: ReactNode
}

export const defaultConfigRef: {
Expand All @@ -26,7 +25,9 @@ export function getDefaultConfig() {

const ConfigContext = React.createContext<Config | null>(null)

export type ConfigProviderProps = Config
export type ConfigProviderProps = Config & {
children?: ReactNode
}

export const ConfigProvider: FC<ConfigProviderProps> = props => {
const { children, ...config } = props
Expand Down
13 changes: 13 additions & 0 deletions src/components/config-provider/tests/config-provider.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import Form from '../../form'
import Picker from '../../picker'
import SearchBar from '../../search-bar'
import ImageUploader from '../../image-uploader'
import { useConfig } from '../'

import zhCN from '../../../locales/zh-CN'
import zhTW from '../../../locales/zh-TW'
Expand Down Expand Up @@ -98,4 +99,16 @@ describe('ConfigProvider', () => {
expect(container).toMatchSnapshot()
})
})

test('useConfig should only has `locale`', () => {
let config: ReturnType<typeof useConfig>

const Demo = () => {
config = useConfig()
return null
}
render(<Demo />)

expect(Object.keys(config!)).toEqual(['locale'])

Check warning on line 112 in src/components/config-provider/tests/config-provider.test.tsx

View workflow job for this annotation

GitHub Actions / check

Forbidden non-null assertion
})
})
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type {
} from './components/checkbox'
export { default as Collapse } from './components/collapse'
export type { CollapseProps, CollapsePanelProps } from './components/collapse'
export { default as ConfigProvider } from './components/config-provider'
export { default as ConfigProvider, useConfig } from './components/config-provider'
export type { ConfigProviderProps } from './components/config-provider'
export { default as DatePicker } from './components/date-picker'
export type { DatePickerProps, DatePickerRef } from './components/date-picker'
Expand Down

0 comments on commit 4a43616

Please sign in to comment.