Skip to content

Access to payload object on plugin initialization #1018

Answered by denolfe
khakimvinh asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @khakimvinh , this is a great question. All config and plugin initialization is done before accessing the backend.

If you need your plugin to perform some sort of action, your plugin could utilize the onInit function of the config, which gives it access to the payload local API. Here is an example:

  onInit: async (payload) => {
    await payload.create({
      collection: 'my-collection',
      data: {
        // Set field values here
      },
    });
  },

Worth noting that if you populate this function inside of your plugin, any other onInit usage will likely be wiped out.

Because this is a function and not a property that can be spread - what I'd recommend is having your plugin exp…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@khakimvinh
Comment options

Answer selected by denolfe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants