Update overview.mdx

This commit is contained in:
James Mikrut
2024-06-24 14:10:00 -04:00
committed by GitHub
parent 2396a70e45
commit fce545bed6

View File

@@ -28,31 +28,7 @@ You can gain access to the currently running `payload` object via two ways:
#### Accessing from args or `req` #### Accessing from args or `req`
<<<<<<< HEAD
In most places within Payload itself, you can access `payload` directly from the arguments of hooks, access control, validation functions, and similar. This is the simplest way to access Payload in most cases. Most config functions take the `req` (Request) object, which has Payload bound to it (`req.payload`). In most places within Payload itself, you can access `payload` directly from the arguments of hooks, access control, validation functions, and similar. This is the simplest way to access Payload in most cases. Most config functions take the `req` (Request) object, which has Payload bound to it (`req.payload`).
=======
You can import or require `payload` into your own files after it's been initialized, but you need to make sure that
your `import` / `require` statements come **after** you call `payload.init()`—otherwise Payload won't have been
initialized yet. That might be obvious. To us, it's usually not.
Example:
```ts
import payload from 'payload'
import { CollectionAfterChangeHook } from 'payload/types'
const afterChangeHook: CollectionAfterChangeHook = async () => {
const posts = await payload.find({
collection: 'posts',
})
}
```
#### Accessing from the `req`
Payload is available anywhere you have access to the `req` - including within your access control and hook
functions.
>>>>>>> e782d9942928c97c3ff567fc311c7d889f8b06d3
Example: Example: