Skip to content

Commit

Permalink
fix(config): deal with array type
Browse files Browse the repository at this point in the history
  • Loading branch information
uyarn committed Mar 1, 2022
1 parent 4ac5f0d commit 34654c6
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/config-provider/ConfigProvider.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import React from 'react';
import _merge from 'lodash/merge';
import ConfigContext, { Config, defaultGlobalConfig } from './ConfigContext';
import _mergeWith from 'lodash/mergeWith';
import ConfigContext, { Config, defaultGlobalConfig, GlobalConfig } from './ConfigContext';

export interface ConfigProviderProps extends Config {
children: React.ReactNode;
}

export const merge = _merge;
// deal with https://github.com/lodash/lodash/issues/1313
export const merge = (src: GlobalConfig, config: GlobalConfig) =>
_mergeWith(src, config, (objValue, srcValue) => {
if (Array.isArray(objValue)) {
return srcValue;
}
});

export default function ConfigProvider({ children, globalConfig }: ConfigProviderProps) {
const mergedGlobalConfig = merge(defaultGlobalConfig, globalConfig);
return <ConfigContext.Provider value={{ globalConfig: mergedGlobalConfig }}>{children}</ConfigContext.Provider>;
Expand Down

0 comments on commit 34654c6

Please sign in to comment.