@@ -16,6 +16,11 @@ export type ContextKey<Z> = InjectionKey<Z> | string
16
16
*
17
17
* @see https://vuejs.org/api/composition-api-dependency-injection.html#inject
18
18
* @see https://0.vuetifyjs.com/composables/foundation/create-context
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * const myContext = useContext<MyContext>('my-context')
23
+ * ```
19
24
*/
20
25
export function useContext < Z > ( key : ContextKey < Z > ) {
21
26
const context = inject < Z > ( key , undefined as Z )
@@ -38,6 +43,11 @@ export function useContext<Z> (key: ContextKey<Z>) {
38
43
*
39
44
* @see https://vuejs.org/api/composition-api-dependency-injection.html#provide
40
45
* @see https://0.vuetifyjs.com/composables/foundation/create-context
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * provideContext<MyContext>('my-context', myContext)
50
+ * ```
41
51
*/
42
52
export function provideContext < Z > ( key : ContextKey < Z > , context : Z , app ?: App ) {
43
53
app ?. provide ( key , context ) ?? provide ( key , context )
@@ -48,12 +58,17 @@ export function provideContext<Z> (key: ContextKey<Z>, context: Z, app?: App) {
48
58
/**
49
59
* Creates a new context for providing and injecting data.
50
60
*
51
- * @param _key The key of the context to create.
61
+ * @param key The key of the context to create.
52
62
* @template Z The type of the context.
53
63
* @returns A tuple containing the `useContext` and `provideContext` functions.
54
64
*
55
65
* @see https://vuejs.org/api/composition-api-dependency-injection.html
56
66
* @see https://0.vuetifyjs.com/composables/foundation/create-context
67
+ *
68
+ * @example
69
+ * ```ts
70
+ * const [provideMyContext, useMyContext] = createContext<MyContext>('my-context')
71
+ * ```
57
72
*/
58
73
export function createContext < Z > ( _key : ContextKey < Z > ) {
59
74
function _provideContext ( context : Z , app ?: App ) {
0 commit comments