Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Access payload instance in server component (Payload 2)?

default discord avatar
rockybalboa305610 months ago
4

Hi,


is it possible to access payload object instance in a server component? For example:



import payload from 'payload'

export default async function Component() {
  const productsCollection = payload.db.collections['products']
  const product = productsCollection.find(...findQuery...)

  return <>...UI goes here...</>
}


It builds but 'payload' is always udefined here.


Can I do something like that or do I need to have an api endpoint that performs that find operation and then I need to simply fetch the data from that endpoint?



Thanks in advance.

Star on GitHub

Star

Chat on Discord

Discord

online

Can't find what you're looking for?

Get dedicated engineering support directly from the Payload team.