Question from @Hendrik : Is it possible to use the local payload api in custom react components in the admin dashboard ui?
@Hendrik so the local API should only be used server-side. For react components there's a bunch of hooks you can use which you can use though - they do something similar!
@Alessio 🍣 basically i try to build a dashboard overview in payload, loading several data from the payload db
Since that's client-side, you can do that with hooks & fetch requests. So first check outhttps://payloadcms.com/docs/admin/hooks#useconfig
- you can use those in your component, especially useConfig.
Also check outhttps://github.com/AlessioGr/payload-plugin-lexical/blob/9c6a7672fd782d39e63139dafef4d6a9454170a2/demo/src/customLexicalFeatures/inlineProduct/nodes/ProductDisplayComponent.tsx#L40
as an example for how I fetch collection data from the payload db. It's just a simple fetch in the end.
Same thing happens in the payload core too, e.g.https://github.com/payloadcms/payload/blob/de2ae5ec15be37b84cdae5ed4e38291e6b2b8123/src/admin/components/views/collections/Edit/index.tsx#L50
You could probably also make a custom endpoint to use the local API and get the data you want. And then fetch from your custom endpoint from your react component
thank you for this detailled answer! 🙂
Get help straight from the Payload team with an Enterprise License.