#best way to access data from client component

16 messages · Page 1 of 1 (latest)

simple kayak
#

if im understanding this correctly, if im on the server i can use the local API
https://payloadcms.com/docs/getting-started/concepts#local-api
but if im on the client my hands are tied a bit (i mean for type saftey), my options are

  1. use the rest api directly (i will lose all the type saftey, unless i make my own wrappers using tanstack query or use somethning like ts-rest, or zodios)
  2. make a trpc server and use local-api and make my own wrappers again
  3. use graphql with apollo to make it generate the hooks for me.
  4. idk, is there is an sdk or something like that i remmber seeing an issue or a pull request on github if im not mistaken

so the question is what is the best way to access the data from client components, like if a user clicked the like button how can i make the mutation and invalidate the likes etc

simple kayak
#

TLDR
a way to access the cms from the client without making my own wrappers, with full type saftey

craggy raft
shell rain
#

Anybody successful in integrating grapesjs to payloadcms? Instead of using lexical richtext.
I have been successful, with the caveat that I’m still trying to resolve is when I’m saving it’s showing different versions in different browsers, which means each time I save that is do an update(patch) it’s creating a new version which is correct but on opening it on another browser it will open previous version thus not showing the latest version changes, if anyone knows how I can resolve this can please contact me at Namitasairam@gmail.com or here, thank you

open saffron
#

@shell rain
Please make a new post with your question. It's not related to this post.

#

Hi, @simple kayak

#

Your backend and frontend are working on the different ports?

simple kayak
#

the most optimal way to my knowldge is forcing trpc in the way

open saffron
#

Why not the use of rest api?

simple kayak
#

how do you get type saftey there?

#

i must make wrappers around each endpoint using react query

#

as@craggy raft said there is a pull request for an SDK to wrap the client side but no one sure is if it's going to be merged + it's more like a general approach than a "reacty way"
https://github.com/payloadcms/payload/pull/9463

GitHub

Adds Payload SDK package, which can be used to query Payload REST API in a fully type safe way. Has support for all necessary operations, including auth, type safe select, populate, joins propertie...

craggy raft
#

I tried TRPC, ORPC before, in a monorepo, frontend is astro. Just adds too much complexity.

Just use the code from the above PR in a package, import the payload config (only the type, which is another workspace package) it is working.