Skip to content

Commit

Permalink
fix: optimize configProvider type writting style (#2383)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislol98 authored Jul 25, 2023
1 parent 6a50b97 commit 2f76f1b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
12 changes: 6 additions & 6 deletions src/config-provider/ConfigContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ export const defaultAnimation = {
exclude: [],
};

export const defaultGlobalConfig = {
type DefaultGlobalConfig = Partial<GlobalConfigProvider>

export const defaultGlobalConfig: DefaultGlobalConfig = {
animation: defaultAnimation,
classPrefix: defaultClassPrefix,
...merge(defaultLocale, defaultConfig),
};

export type Locale = typeof defaultLocale;

export type GlobalConfig = typeof defaultGlobalConfig;
export interface Config {
globalConfig?: GlobalConfigProvider;
}

export const defaultContext: { globalConfig: GlobalConfig } = {
export const defaultContext = {
globalConfig: defaultGlobalConfig,
};

export type Config = typeof defaultContext;

const ConfigContext = createContext(defaultContext);

export default ConfigContext;
4 changes: 2 additions & 2 deletions src/config-provider/ConfigProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import _mergeWith from 'lodash/mergeWith';
import ConfigContext, { Config, defaultGlobalConfig, GlobalConfig } from './ConfigContext';
import ConfigContext, { defaultGlobalConfig, Config } from './ConfigContext';
import { GlobalConfigProvider } from './type';

export interface ConfigProviderProps extends Config {
Expand All @@ -18,7 +18,7 @@ export const merge = (src: GlobalConfigProvider, config: GlobalConfigProvider) =
export default function ConfigProvider({ children, globalConfig }: ConfigProviderProps) {
const mergedGlobalConfig = merge(defaultGlobalConfig, globalConfig);
return (
<ConfigContext.Provider value={{ globalConfig: mergedGlobalConfig as GlobalConfig }}>
<ConfigContext.Provider value={{ globalConfig: mergedGlobalConfig }}>
{children}
</ConfigContext.Provider>
);
Expand Down

0 comments on commit 2f76f1b

Please sign in to comment.