#What's the best way to use Payload local API in a custom component?

8 messages · Page 1 of 1 (latest)

teal timberBOT
proud inlet
#

Context: I'm producing a plugin that will add a view to the config.admin.components and it's within this component I want to use the local API.

export default (pluginConfig: PluginConfig): Plugin =>
  config => {
    const updatedConfig: Config = {
      ...config,
      admin: {
        ...config.admin,
        components: {
          ...config.admin?.components,
          views: {
            ...config.admin?.components?.views,
            MigrateExportView: {
              Component: ({ user, canAccessAdmin }) =>
                React.createElement(MigrateView, { user, canAccessAdmin, migrateType: 'export' }),
              path: '/migrate/export',
            },
            MigrateImportView: {
              Component: ({ user, canAccessAdmin }) =>
                React.createElement(MigrateView, { user, canAccessAdmin, migrateType: 'import' }),
              path: '/migrate/import',
            },
          },
        },
      },
    }

    return deepmerge(updatedConfig, pluginConfig.overwrites || {})
  }

upper mango
#

@proud inlet you won’t be able to use the local api in a react component if that’s what you mean? Instead you’ll want to use the rest or GraphQL api

acoustic relic
proud inlet
proud inlet
teal timberBOT
acoustic relic