ant-design-vue/components/_util/createContext.ts

18 lines
360 B
TypeScript
Raw Normal View History

2022-05-10 08:18:44 +00:00
import { inject, provide } from 'vue';
function createContext<T>() {
const contextKey = Symbol('contextKey');
const useProvide = (props: T) => {
provide(contextKey, props);
};
const useInject = () => {
return inject(contextKey, undefined as T) || ({} as T);
};
return {
useProvide,
useInject,
};
}
export default createContext;