pingdotgg / zact

Nothing to see here
https://zact-example.vercel.app
MIT License
980 stars 16 forks source link

Added a client for grouping zacts and initZact to allow for shared middleware #4

Closed ivoilic closed 1 year ago

ivoilic commented 1 year ago

Stumbled on this repo and love the concept. Thought it might be nice to have a centralized way to organization/access all your actions rather than having to import both the action and the hook each time. Hope you like it, let me know if you have any thoughts or ideas!

vercel[bot] commented 1 year ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
zact-example ❌ Failed (Inspect) Apr 13, 2023 3:43am
t3dotgg commented 1 year ago

👀

ivoilic commented 1 year ago

Updated the readme with a client example. @t3dotgg, I'd love to help more on this project. I know it's pretty early but let me know if there is anything specific I can do: code, docs, logo etc.

ivoilic commented 1 year ago

Tried using this in an actual project and realized there were react hook issues that hadn't been caught by eslint. Also added a way to use middleware!

t3dotgg commented 1 year ago

@ivoilic yeah you have to prefix the caller with use for it to work, that's why I went with the useMutation(namedMutation) pattern. Same reason tRPC mutations in React have to end with useMutation. Also fun fact: many linters only work if the function STARTS with use, i.e. useQuery(trpc) works buttrpc.useQuery()` does not 😅

If we were to pursue something like this, my preferred pattern would be something more like useZact(client.someMutation) - at which point you can kind of just define an object and be done with it

ivoilic commented 1 year ago

@t3dotgg Thank you so much for taking the time to check this and out and for the info! Totally understand your preference on this.