Skip to content

Commit 37b41af

Browse files
committed
refactor(react-ui): 使用 useLocale 代替 useContext
1 parent f9a0bc4 commit 37b41af

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

packages/components/src/calendar/Calendar.tsx

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import {
44
getClasses,
55
useWatch,
66
} from '@pkg/shared';
7-
import type { CalendarLocale, CalendarProps } from './calendar.types';
87
import { getStartOfMonth, getClassNames } from '@tool-pack/basic';
9-
import { ConfigContext } from '~/config-provider/config.context';
108
import { CalendarHeader } from '~/calendar/components/Header';
9+
import { useLocale } from '~/config-provider/useLocale';
10+
import type { CalendarProps } from './calendar.types';
1111
import { CalendarTable } from '~/calendar/components';
1212
import type { RequiredPart } from '@tool-pack/types';
13-
import React, { useContext, useMemo } from 'react';
14-
import calendarLocale from './locale/en-US';
13+
import EnUS from './locale/en-US';
14+
import React from 'react';
1515

1616
const cls = getClasses('calendar', ['date-cell'], ['prev-month', 'next-month']);
1717
const defaultProps = {
@@ -24,7 +24,6 @@ export const Calendar: React.FC<CalendarProps> = React.forwardRef<
2424
HTMLDivElement,
2525
CalendarProps
2626
>((props, ref) => {
27-
const contextLocale = useContext(ConfigContext).locale;
2827
const {
2928
locale: propsLocale,
3029
month: propsMonth,
@@ -38,11 +37,7 @@ export const Calendar: React.FC<CalendarProps> = React.forwardRef<
3837
value,
3938
} = props as RequiredPart<CalendarProps, keyof typeof defaultProps>;
4039

41-
const locale = useMemo<CalendarLocale>(
42-
() =>
43-
Object.assign({}, calendarLocale, contextLocale.calendar, propsLocale),
44-
[contextLocale.calendar, propsLocale],
45-
);
40+
const locale = Object.assign(useLocale('calendar', EnUS), propsLocale);
4641

4742
const [valueRef, setValueRef] = useStateRef(value);
4843
const [month, setMonth] = useFollowingState(

packages/components/src/pop-confirm/PopConfirm.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import { ConfigContext } from '~/config-provider/config.context';
21
import { getComponentClass, useVisible } from '@pkg/shared';
32
import type { PopConfirmProps } from './pop-confirm.types';
3+
import { useLocale } from '~/config-provider/useLocale';
44
import type { RequiredPart } from '@tool-pack/types';
5-
import React, { useContext, useEffect } from 'react';
65
import { Layout, Footer, Main } from '~/layouts';
76
import { CircleInfoFill } from '@pkg/icons';
7+
import React, { useEffect } from 'react';
88
import { Popover } from '~/popover';
99
import { Button } from '~/button';
1010
import enUS from './locale/en-US';
@@ -33,7 +33,7 @@ export const PopConfirm: React.FC<PopConfirmProps> = (props) => {
3333
const _confirm = confirmProps ?? {};
3434
const _cancel = cancelProps ?? {};
3535

36-
const locale = useContext(ConfigContext).locale.popConfirm || enUS;
36+
const locale = useLocale('popConfirm', enUS);
3737
const [visible, hide, setVisible] = useVisible(outerVisible);
3838

3939
useEffect(() => {

0 commit comments

Comments
 (0)