motion-v
Version:
<p align="center"> <img width="100" height="100" alt="Motion logo" src="https://user-images.githubusercontent.com/7850794/164965523-3eced4c4-6020-467e-acde-f11b7900ad62.png" /> </p> <h1 align="center">Motion for Vue</h1>
25 lines (24 loc) • 918 B
JavaScript
import { inject, provide } from "vue";
function createContext(providerComponentName, contextName) {
const symbolDescription = typeof providerComponentName === "string" && !contextName ? `${providerComponentName}Context` : contextName;
const injectionKey = Symbol(symbolDescription);
const injectContext = (fallback) => {
const context = inject(injectionKey, fallback);
if (context === void 0) {
throw new Error(
`Injection \`${injectionKey.toString()}\` not found. Component must be used within ${Array.isArray(providerComponentName) ? `one of the following components: ${providerComponentName.join(
", "
)}` : `\`${providerComponentName}\``}`
);
}
return context;
};
const provideContext = (contextValue) => {
provide(injectionKey, contextValue);
return contextValue;
};
return [injectContext, provideContext];
}
export {
createContext
};