@alicloudfe/components
Version:
A react component library for aliyun
29 lines (28 loc) • 1.15 kB
JavaScript
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
import React, { useContext } from 'react';
import hoistNonReactStatics from 'hoist-non-react-statics';
import ConfigProvider from '../config-provider';
var ctx = React.createContext(null);
export function withFusionConfig(Comp) {
var Wrapper = React.forwardRef(function (props, ref) {
var ConfifgConsumer = ConfigProvider.Consumer;
return (React.createElement(ConfifgConsumer, null, function (context) { return (React.createElement(ctx.Provider, { value: context },
React.createElement(Comp, __assign({}, props, { ref: ref })))); }));
});
hoistNonReactStatics(Wrapper, Comp);
return Wrapper;
}
export function useFusionConfig() {
var ctxValue = useContext(ctx);
return ctxValue || ConfigProvider.getContext() || {};
}