Skip to content

Allow Wrapping the Root Component with a Global Context Provider in Addons #2041

@sghng

Description

@sghng

Is your feature request related to a problem? Please describe.

When creating addons that introduces other component libraries, some will require a context provider to enable the full capability of the libraries. e.g. to provide themes. Currently, seems like we only have control on the app object, (can do app.use(), etc), but we don't have access to the definition of the app itself.

Describe the solution you'd like

Give a config function for wrapping global context provider:

import { h, type Component } from "vue";

export function defineGlobalProvider(
  wrapper: (appRoot: Component) => Component
) {
  return (appRoot: Component) => wrapper(appRoot);
}

This should be put in createApp()

And the configuration will look like:

// main.ts
defineGlobalProvider((rootComponent) => ({
  render() {
    return h(MyGlobalProvider, null, () => h(rootComponent));
  },
}));

See also in:

#2039

tusen-ai/naive-ui#6733

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions