I'm trying to build a plugin for Payload that provides hooks for collection.
Problem is that I'm using local API inside hooks and when trying to access
it returns an empty object
object was imported like
import payload from 'payload'
How can I use local API inside plugin?
Payload needs to be initialized before you can use its local API - so when your plugin instantiates, that isbefore
Payload becomes fully initialized
you should use the
method of the config instead if you need to interact with the local API inside of a plugin
So I can make function for onInit that will save reference to payload and use that reference instead?
comes through as an argument to that function
yes, but I need to use payload in other functions, that were added to collections as hooks before onInit
that's fine too
because when those hooks are actually executed, payload willhave been already initialized
note that you can also get payload off
is an arg to hooks
thats actualy better
Yep, that helped, thank you!