You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
379 B
18 lines
379 B
import { inject, provide } from 'vue';
|
|
|
|
function createContext<T>(defaultValue?: T) {
|
|
const contextKey = Symbol('contextKey');
|
|
const useProvide = (props: T) => {
|
|
provide(contextKey, props);
|
|
};
|
|
const useInject = () => {
|
|
return inject(contextKey, defaultValue as T) || ({} as T);
|
|
};
|
|
return {
|
|
useProvide,
|
|
useInject,
|
|
};
|
|
}
|
|
|
|
export default createContext;
|