Тёмный

Fetching Data Doesn't Get Better Than This 

Josh tried coding
Подписаться 137 тыс.
Просмотров 60 тыс.
50% 1

About a month ago I discovered that this data fetching pattern even works, and I'm not going back. This approach is
- type safe
- intuitive
- fast
The only downside I've discovered since is that it doesn't work for webhooks as they NEED to be an API, but other than that, god damn this is great.
-- my links
second channel (in depth videos): / @joshtriedupstash
discord: / discord
github: github.com/joschan21

Наука

Опубликовано:

 

15 май 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 255   
@cb73
@cb73 16 дней назад
“mutate” isn’t intuitive because it wasn’t really meant for get requests it’s meant for creating and updating data.
@BeyondLegendary
@BeyondLegendary 17 дней назад
Impressive, very nice. Let's see Paul Allen's data fetching pattern.
@entropysquare9683
@entropysquare9683 17 дней назад
_Look at this sublte inclusion of type safety , the tasteful thickness of it._ *Oh my god!* _It even has the loading and error states handled by react-query._
@joshtriedcoding
@joshtriedcoding 17 дней назад
@@entropysquare9683 something wrong, man? you're sweating
@Its-InderjeetSinghGill
@Its-InderjeetSinghGill 16 дней назад
@@joshtriedcodingleave bro him bro. He just a sad little junior dev who’s trying to get some attention. Just keep doing great work ❤
@stewart6395
@stewart6395 15 дней назад
@@joshtriedcoding how long has your channel been up? It seems like you've just discovered react-query and talking about it like it's something incredible. It's silly and funny at the same time (I think that's what the guy was trying to say, it's called sarcasm)
@gamevidzist
@gamevidzist 14 дней назад
Can somebody explain the Paul Allen thing
@pizzatime7455
@pizzatime7455 17 дней назад
Not sure why you're using a mutation when this looks like a query
@outis99
@outis99 16 дней назад
Sometimes you want to perform a GET request when a user clicks a button for example. You can't really control when a useQuery runs unless you specify the enabled property
@tyagoluizz
@tyagoluizz 16 дней назад
​@@outis99 There are ways to do that from query (if i'm not mistaken). useQuery exports a "refetch" function for that. We can also invalidate the specific query key using queryClient (useQueryClient). And there might be other ways. I might not be right about this, but as far as i know, mutate are intended for post, put, etc. If anyone has a deeper understanding about react-query, i'm here to learn :D
@StabilDEV
@StabilDEV 15 дней назад
@@outis99 server actions are always POST requests
@josepazmino842
@josepazmino842 14 дней назад
​@@StabilDEV I guess what he means is that with useQuery the query performs when the component is mounted and if yout want to controll it yout need to pass the enabled property and use refetch but with useMutation you just need to use the mutate function.
@travistarp7466
@travistarp7466 14 дней назад
@@josepazmino842 yes, but the reason hes using useMutation is not for this reason. Like Stabildev said, all server actions are post so you can't use useQuery.
@codinginflow
@codinginflow 17 дней назад
My new favorite way of fetching data is with infinite loading through a server action. 10x devs use POST requests to get data.
@samislam2746
@samislam2746 16 дней назад
That's a problem
@stouser1296
@stouser1296 14 дней назад
10x devs use 500 to denote successful request on api endpoint
@hyperprotagonist
@hyperprotagonist 17 дней назад
Amazing! Thanks to this video I went from Apprentice Brick Layer to Senior-Seasoned Full-Stackoverflow-BackToFront-End Devengineer and ready for retirement.
@raymrash
@raymrash 16 дней назад
😂😂😂
@nobodysaysmynameright
@nobodysaysmynameright 11 дней назад
Hi Josh. My main problem with this approach is data consumption and download speed / execution time, which may or may not be a concern depending on where you operate. I'm currently working for a client in Zambia and Malawi which is known for their expensive data and lack of network availability, so everything counts. As a test, I made both server action and /api route return the same payload ({foo:"bar"}}, both using POST (a restriction of server actions) and there are the results: - server actions - 447B download size - 84ms to respond - /api/ route - 192B download size - 25ms to respond As the request in server actions points to the route itself it's likely running much more code than the /api route which just returns some JSON. That said 100% agree this is a much better DX with types flowing through and love to see new and creative approaches to current problems!
@kamill34
@kamill34 16 дней назад
server actions are not made for fetching data, for this case better use "server only", (it is not provided by default). Basically you can achieve the same using native fetch and built in loading, suspense, error boundary. The big difference is because you use a hook, you are not more purely on server side, this require directive "use client", but your approach is much cleaner.
@viral_recaps
@viral_recaps 17 дней назад
Combination of Tanstack/react-query and next js server action would make my life so much easier.
@devinsights8021
@devinsights8021 17 дней назад
usemutation for getting data? lol, what about in memory cache?
@TheBelafleck
@TheBelafleck 11 часов назад
You can use this approach with useQuery as well 👍
@Mr8000D
@Mr8000D 16 дней назад
You can also add a type to the useMutation like useMutation It seems like the reason this works in the video is because typescript can infer the types from the getUser function you defined. Still a nice pattern! Thanks for sharing!
@derkaouiabdelatif1524
@derkaouiabdelatif1524 16 дней назад
I scrolled down the comments just to make sure someone mentioned this haha
@NarcisMM
@NarcisMM 16 дней назад
Yeah but that would mean you have to maintain the types.
@JoshuaWeidema
@JoshuaWeidema 15 дней назад
@@derkaouiabdelatif1524lol ditto
@Gabriel-kl6bt
@Gabriel-kl6bt 15 дней назад
I am still not fond of writing back-end code with Next.js. I simply do not see it becoming manageable as the project grows in size and complexity. It seems to be more suitable for a small-scale project, such blogging, with minimal logic, where using a large-scale framework, such as .NET or Spring Boot, would indeed be an overkill. Furthermore, I followed the official tutorial from Next.js' website and there they even wrote SQL code, an approach that reminded me of when I started learning how to code with PHP, and I would write SQL, PHP, and HTML all together. It was about 10 years ago or so. A simple CRUD, tops.
@wandie87
@wandie87 14 дней назад
Mutations are meant to be used for creating or altering data -- i.e to mutate it., not for fetching data. Fetching data should use useQuery. POST, PATCH, PUT requests should use useMutation.
@SlowedOutOfExistence
@SlowedOutOfExistence День назад
instead of using react-query I would just implement a custom hook for the project that reduce redundancy and track request state. You can make it typed for typescript easily with a generic function, like
@refeals
@refeals 17 дней назад
I guess the only "drawback" is that it only works in client components, since it's a hook. But still a pretty great solution, I absolutely love react query!
@redeemr
@redeemr 16 дней назад
Is that really a drawback? You can just run fetch directly in a server component
@refeals
@refeals 16 дней назад
@@redeemr that's why I put it on quotes xD
@teeldinho471
@teeldinho471 16 дней назад
@@redeemr does this mean you must maintain the same tags on the Tanstack Query side and Server Actions? How does this look in practice, to minimize the need to manage 2 caches?
@SuperSniffen
@SuperSniffen 16 дней назад
​@@teeldinho471 Pretty sure you have to manage 2 caches
@DigitawGamer
@DigitawGamer 15 дней назад
@@teeldinho471 Well, you could just not use Next.js cache, passing "no-store" to your fetchs or using some lib that doesn't depend on fetch like Axios to make requests.
@0xOmzi
@0xOmzi 10 дней назад
This is really cool Josh! Thanks for sharing ;).
@rasmic
@rasmic 17 дней назад
Legit been doing this for time, I'm glad this got Josh's cosign ;)
@GearIntellixTV
@GearIntellixTV 16 дней назад
Amazing! Is possible to protect the server action with authentication? For eg. Create task action cannot be used before you logged in
@chrisbirkenmaier2277
@chrisbirkenmaier2277 16 дней назад
Nice one. Question: In comparison, how do you feel about the t3-stack, or TRPC in general? Sounds like a very similar approach.
@AndersGustafsson87
@AndersGustafsson87 13 дней назад
yep its similar... server actions are simply auto-generated api routes, same as trpc. So in my opinion its just a less mature alternative. The only thing server actions have going for them is they are "native to the framework" and hence can do revalidateTag() and notify the client to do the router.refresh() equivalent automatically.
@AStranger77
@AStranger77 17 дней назад
What do you think about react-query in combination with hono? Maybe not so simple like server actions but much more cleaner and also type-safe.
@rewix4101
@rewix4101 17 дней назад
This looks great! However, doesn't react query provide support for typescript using generic types? I personally love extracting every useState and useMutation with fetching logic into separate hook, which take as a parameter the query options object (which also has special type provided by react query), therefore making those hooks highly reusable across many different components due to their customizability.
@ankursehdev5448
@ankursehdev5448 16 дней назад
Would you still use Mutation if the data needs to be loaded on the pageLoad? As per my understanding, mutations are generally used for CRUD operation with server and not really for data fetching.
@cptn-nemo
@cptn-nemo 17 дней назад
Yep, I didnot used server actions with react query. I have one question, should i still use next-safe-actions thats another library, will be sever actions safe if i wont use that library?
@cptn-nemo
@cptn-nemo 17 дней назад
I meant if i only use react query and not that lib "next-safe-actions". is this good for security?
@ofonna
@ofonna 16 дней назад
Tan stack query hooks actually do a pretty good job inferring types, in some special cases you might need to pass generic parameters for type safety, but you can definitely use them without the server action combination.
@chasehelton5462
@chasehelton5462 17 дней назад
Do you typically separate out your server actions into separate files or just include them all in an "actions.ts" file? I'm curious how you prefer to structure your files/folders in general, I'd love to see a video on that at some point!
@younelo9811
@younelo9811 17 дней назад
interested
@ExileEditing
@ExileEditing 16 дней назад
Also interested. Currently I have my actions in /server/actions with each being grouped somehow if possible. Grouped based on table names or something. But I've seen one file and I've seen a single actions.ts in the same directory as the page using that action
@notammo
@notammo 16 дней назад
Does this help with "protecting" an api key, so the user cannot just simply take it out of the network tab? If not, do you have any recommendations on how to implement client side actions like updating, deleting, etc. without exposing the token to the client?
@gamingwolf3385
@gamingwolf3385 17 дней назад
Its nice but our component will be client side , not server side and our react query is still big dependency to use in our components
@vasyaqwe2087
@vasyaqwe2087 17 дней назад
This is great, I’ve been using this. Once you need to protect the mutations, schema validation or some kind of middleware, I’ve found trpc to be the best option. You can call trpc mutations in server actions. If you’re not using react query, then next-safe-action is a good choice
@ondrej.drapalik
@ondrej.drapalik 17 дней назад
I second this trpc api all the way. Schema validation is a pain writing manually and what's more important consistently.
@kingsleykelechionwuchekwa7508
@kingsleykelechionwuchekwa7508 16 дней назад
Or just use next-safe-actions
@ShubhamShubham-gg9fj
@ShubhamShubham-gg9fj 17 дней назад
Hey Josh, I definitely like this approach but the NEXT team are saying "handle form submissions and data mutations" and i have seen around the internet to not to use for as "GET" use only as Mutation function and so, What are your thoughts on this. Is it really a thing to use only as a Mutation or we can do whatever inside it without worrying about these things?
@vasyaqwe2087
@vasyaqwe2087 17 дней назад
I’ve tried using actions for getting data. Went back to using usual fetch. Reason? Server actions are executed sequentially, they can not run in parallel. And any other user interaction will be blocked until action is done. This has a huge impact on performance😕 Also, POST requests don’t really have the caching benefits of GET requests
@ahmednabil4456
@ahmednabil4456 17 дней назад
And there is no caching on server actions
@ShubhamShubham-gg9fj
@ShubhamShubham-gg9fj 17 дней назад
Thanks guys. My doubt is cleared now. But is there any way to get type safety for this use case? (other than trpc)
@joshtriedcoding
@joshtriedcoding 17 дней назад
honestly i dont follow closely what they say, i feel like this approach is awesome and its so productive
@abdikanimohamed436
@abdikanimohamed436 16 дней назад
❤​@@vasyaqwe2087
@tegasteve8195
@tegasteve8195 17 дней назад
Well and very well explained, thanks so much
@luisguareschi5104
@luisguareschi5104 16 дней назад
I like the idea, but why would you use a mutation function to get data? Why not use the useQuery hook to get the data in that example? Apart from that the idea is very good!
@fitimbytyci345
@fitimbytyci345 16 дней назад
+1, I use useQuery and pass a server action to it so we get the data on component render and not depend on user actions to fetch data.
@DigitawGamer
@DigitawGamer 16 дней назад
@@fitimbytyci345 You're doing it right in this case, but don't forget mutations when the data will be created/updated/deleted with users actions, it's easier to implement optimistic updates with it.
@user-bj1rj4rv3k
@user-bj1rj4rv3k 4 дня назад
This is useful for me! Thanks Josh
@origaming6379
@origaming6379 14 дней назад
can i have someone opinion on my approach? like im using server actions for fetching data and in pages.tsx is server component which i use the server actions function, and im passing the data trough props to specific component inside page.tsx which all the components here is client side component. then rendering the data in this client side. is this a good approach? and with react-query could it run on server components?
@BorrisTrendyWiria
@BorrisTrendyWiria 16 дней назад
is this working if we disable JS? i thought the benefit of server actions is to be able still to mutate even if user does not run JS
@ahmedaq9018
@ahmedaq9018 16 дней назад
I think Upstash are lucky to have you in their team.. Amazing tutorial Josh 🎉
@user-iv3uc7cw7n
@user-iv3uc7cw7n 15 дней назад
I have a problem, if you want to handle errors, in Server action directly throw errors in development mode can, But in production mode the error message will be hidden, how to solve?
@chiragchhajed8353
@chiragchhajed8353 17 дней назад
While not sure about react query, RTK query does give the ability to add types for both response types and query args with all the isLoading, error, etc states
@Weagle1337
@Weagle1337 17 дней назад
Yes, React Query also has that ability, but inference is just better
@StemLG
@StemLG 17 дней назад
been using this for a while too it's pretty cool
@TheGrandChieftain
@TheGrandChieftain 17 дней назад
I found setting up TRPC a nightmare with inadequate documentation, so I’ve just been exporting/importing types all this while. But this is actually a killer combo - thank you so much!
@joshtriedcoding
@joshtriedcoding 17 дней назад
same dude!! tRPC is such a nice tool but the setup has been so unintuitive for me too. appreciate ya
@samwise8731
@samwise8731 16 дней назад
It takes like 2 mins or less to setup trpc
@srleom
@srleom 16 дней назад
Use T3 stack.
@rmcoder23
@rmcoder23 16 дней назад
woah thanks Josh for sharing this incredible technique for fetching data way easier than creating api routes, Im already tired of doing bunch of routes lol.
@brennerpablo
@brennerpablo 9 дней назад
You can wrap ReactQuery hooks inside of your own custom hooks, then you can get type safety and any additional business logic, or statuses you need before returning to the page components. I will keeping using this pattern + api routes for now, still not seeing benefits from server actions, and it is a lot less intuitive to use.
@kukiponosanhrvat
@kukiponosanhrvat 17 дней назад
This is excellent if you have project which is browser only, but if project get bigger, and mobile app is needed i think server actions might be problematic. Please correct me if im wrong.
@Ikakoo2410
@Ikakoo2410 15 дней назад
what benefit does "use server" directive have in getUser function? what if instead of making it a server action we made it a normal function without "use server" directive?
@__Gojo___
@__Gojo___ 16 дней назад
Wow new learning from you thanks ❤❤
@abdikanimohamed436
@abdikanimohamed436 16 дней назад
Mind blowing 🤯 I can't believe josh how you you teaching and also how you making awesome videos such like this video awesome ❤
@flnnx
@flnnx 16 дней назад
If you don't need caching or invalidation you can even invoke the server action within a custom handler without using RTK mutations, but you have to set a custom loading state, which kinda sucks tho. Also there's some weird errors that occur on the form html element when using server actions directly on them, which is really annoying. So yeah. Invoking actions inside handlers/useEffect or simply react query is much more preferable.
@meka4996
@meka4996 16 дней назад
The best data fetching method in Nextjs! Thanks!
@naksuy
@naksuy 16 дней назад
Pls someone tell me the right way to fetch data in server components. I currently fetch directly from my db on the server side but I noticed there’s no caching.
@rakibtweets
@rakibtweets 17 дней назад
This is amazing, Thanks for sharing...
@user-pc5xt3gc7z
@user-pc5xt3gc7z 17 дней назад
Hmm why tanstack query isn't typesafe (btw why use useMutation for plain fetching?) ? You can specify types for response where you set up your API handlers/ query functions (and by sharing type declaration across front and beckend you can get typesafety if you wnat/need across both project even if they are separate)
@peacemurder3778
@peacemurder3778 17 дней назад
I think it's meant to be a post request but getUser is a bad example for that. Also like you said, you could just specify the data type returned by the fetch request as a typescript interface, so this seems like he's demonstrating a benefit that isn't actually a benefit unless he's assuming we are working with JavaScript and not TypeSrcipt I guess
@user-cy4ks2vm7c
@user-cy4ks2vm7c 17 дней назад
I don’t know. With my implementations I make my mutations typesafe without server action. Just react query
@travistarp7466
@travistarp7466 14 дней назад
But then you have to create your own types when the code is already giving you the types. This method gets the types from the code/libraries. However the downside of this method, like you mentioned, is it uses only post requests(server actions are only post req) which don't cache. If you want 'type safety' either use trpc, server components, or validate with zod. This is mostly a dx issue anyways, your method works fine if done properly.
@muhammadsalmanafzal9396
@muhammadsalmanafzal9396 17 дней назад
could it possibly replace the trpc as a whole? this combination of server actions and react query?
@merveillevaneck5906
@merveillevaneck5906 16 дней назад
Possible. Especially if used in combination with cookies for authentication so you can fetch the current session anywhere on the server. But also im realizing that server actions are executing sequentially and not in parallel. What do you think?
@victorbiasibetti
@victorbiasibetti 13 дней назад
is great for accomplished your API code with your Presentation code - like a junior dev
@dimitartanev97
@dimitartanev97 10 дней назад
Do you think it's a good idea to call an external API from from the server action?
@TheBlackManMythLegend
@TheBlackManMythLegend 14 дней назад
I am old school developer. I just put Mvc everywhere it works everywhere. For everything.
@sebap_xc
@sebap_xc 16 дней назад
What about server components, query inside metadata, HydrationBoundary and prefetch query, cache concerns between next/fetch and RQ? would be great if you could cover all fetching aspects :) All the best
@robboten
@robboten 16 дней назад
How would you use this pattern for external APIs?
@ozqurozalp
@ozqurozalp 17 дней назад
What about error handling with useMutation? Server actions only returns plain objects. You did not mention that?
@user-iv3uc7cw7n
@user-iv3uc7cw7n 17 дней назад
you can throw errors on your own
@ozqurozalp
@ozqurozalp 17 дней назад
@@user-iv3uc7cw7n yeah I know I wrote a simple actionWrapper function that throws for mutation, but I just wonder how other people do that 😃
@helleye311
@helleye311 16 дней назад
Didn't know react query works with server actions, that's great! Only downside is, server actions are always POST, which doesn't make much sense. I mean, you can get data on the server, but if you're using react query and want to have any sort of dynamic loading going on, you'll still need GET endpoints for actual queries. I mean, maybe not *need*, but I refuse to ever fetch data with POST. I'd honestly stick to the default verbose server actions (maybe wrapped behind a custom hook) if only they stopped using FormData. That api has been growing on me, but I really don't want FormData.
@cihadp
@cihadp 15 дней назад
haha: function useTypeSafeActionState(serverAction: T, initialState: U): [state: ReturnType | U, formAction: something] { return useActionState(serverAction, initialState) } Typesafe now within 3 lines.
@AnindoSarker
@AnindoSarker 14 дней назад
We've been using this pattern without server actions for a long time. I can share our project structure if you're interested
@imbaedin
@imbaedin 17 дней назад
Pairing this with initialData sounds OP. And also exporting the queryOptions from the action itself.
@user-cy4ks2vm7c
@user-cy4ks2vm7c 17 дней назад
If by query options you mean the data, loading and error states, it won’t work in app router as actions are to be defined on server and hooks on the client
@michaelschimpelsberger1093
@michaelschimpelsberger1093 13 дней назад
I think that server actions are called sequentially and not in parallel by Next (since that is considered to be most appropriate for mutations). So, this pattern might introduce really bad client-server waterfalls and lead to poor performance.
@ScriptCodec
@ScriptCodec 15 дней назад
Your energy is top-notch 😅😅
@lonelyboy4033
@lonelyboy4033 16 дней назад
Does it have any effect on caching responses?
@PraiseYeezus
@PraiseYeezus 17 дней назад
I like this approach but I have a feeling the default method of a server action being POST can cause issues somewhere.
@rust2411
@rust2411 15 дней назад
What if you didn’t use use server directive in actions file that would still be the same no?
@rust2411
@rust2411 15 дней назад
Anyone? What if getUser isnot a server action and is just normal function?
@user-xe9xx8zj6i
@user-xe9xx8zj6i 17 дней назад
I have been using it for quite some time and here is video about it )
@dearfrankg
@dearfrankg 17 дней назад
I'm seeing that others are having issues with this in the comments - I would like to see your feedback. Thanks
@lovrozagar3729
@lovrozagar3729 17 дней назад
What is the benefit of using server actions for fetching instead of TRPC?
@FIash911
@FIash911 17 дней назад
i don't see any also
@nechtinejebe
@nechtinejebe 17 дней назад
Good question
@Pasko70
@Pasko70 16 дней назад
😮 smooooth 😂 I love the workflow
@cone2571
@cone2571 13 дней назад
Basic react query with Redux. There is such a close connection in syntax.
@gautamjakhar3219
@gautamjakhar3219 16 дней назад
what if i have a nestjs server ? it will not work... again I have to give types on server actions
@PatrickLenart
@PatrickLenart 16 дней назад
The problem is, that it‘s always a post-request. Isn‘t it better to use Hono/ElysiaJS in the API-route like you did in another video? I am trying ElysiaJS at the moment and the „eden treaty“ is amazing. You can use it in react-query and in react server components. This way you can use middleware and all other stuff, you are used to on api-servers. And it‘s easy to seperate them if needed.
@nikako1889
@nikako1889 17 дней назад
use zod for validation and type safety?
@frontend_ko
@frontend_ko 16 дней назад
Thanks for nice tips
@massimopa
@massimopa 17 дней назад
This approach makes sense with mutations, but how would this work with fetching a query? afaik 'data' in useMutation works differently, it is "the last successfully resolved data for the mutation", and since it doesn't make sense to call 'mutate' on a query, how do you get the data? I would love to have a similar approach for simple GETs, that doesn't involve using server components and giving up on react-query and its loading state management
@DigitawGamer
@DigitawGamer 16 дней назад
It works the same, with useQuery you pass a server action to the queryFn, the query will be called automatically when the component renders just like any query.
@shubhankartrivedi
@shubhankartrivedi 16 дней назад
Title should be changed to "Mutating Data Doesn't Get Better Than This"
@FilipCordas
@FilipCordas 11 дней назад
Wow pretty soon next.js will be able to do things I could do 15 years ago in asp web forms amazing.
@muhammedmaher6704
@muhammedmaher6704 17 дней назад
Wow! I think this has the potential to eliminate the need for tRPC. That means zero configuration for Front and Back type-safety, and less bloated full-stack projects. It's amazing to say the least! 🔥
@sarthak-roy
@sarthak-roy 17 дней назад
I was using this moethod in my project but it was not working in vercel. So, switched back to api routes
@naranyala_dev
@naranyala_dev 14 дней назад
create a josh stack please, a community driven open-source
@TheBelafleck
@TheBelafleck 11 часов назад
Thanks for the tip 👍
@FranciscoMarcosMilhomemAbreu
@FranciscoMarcosMilhomemAbreu 16 дней назад
But what about use the same backend for mobile apps?
@y.m.o6171
@y.m.o6171 16 дней назад
amazing content. can you please show how to use this in a pure react full stack app ?
@mishy254
@mishy254 16 дней назад
Josh👌 Very Helpful
@Chris-zt4ol
@Chris-zt4ol 14 дней назад
Congratulations, you just reinvented tRPC
@27sosite73
@27sosite73 16 дней назад
all this is nice, but we just not using useMutation as it is supposed to be used. (we have to mutate with useMutation) why just dont pass server action (that in your case gets data) to queryFn? const query = useQuery({ queryKey: ['todos'], queryFn: __your_server_action_getting_data__ }) and one more thing, even though it works server actions are idiomaticaly used basicaly like a post request (mutate data) - from documentation (not to get data) god knows if it is ok use it in production for now
@royz_1
@royz_1 16 дней назад
Any benefit over trpc?
@ustav_o
@ustav_o 17 дней назад
i use next built in swr. it does the job
@thegrumpydeveloper
@thegrumpydeveloper 12 дней назад
I like the server prefix.
@lucasfranzolin
@lucasfranzolin 16 дней назад
God bless you! Very clean solution LOL
@imkir4n
@imkir4n 16 дней назад
I was the doing the same, its really a good pattern for fetching data.
@milos018
@milos018 16 дней назад
Nuxt 3 has it all built-in, way less complex great typesafe DX
@matanon8454
@matanon8454 16 дней назад
BuT ReAcT more jobs !!!
@pcotrades
@pcotrades 6 дней назад
What about the loading state? What about the error state? I can't relate to these problems cause I use Svelte 😊
@Furki4_4
@Furki4_4 17 дней назад
looks great and similar to the idea used in t3-app actually.
@2dstencil847
@2dstencil847 16 дней назад
It is suppose nodejs and js(frontend backend) work similarly then when both move to typescript safe type, it should too. but new framework dont copy old stuff that good. This kind of pattern already exist from 10 year ago from knockoutjs , emberjs etc. Because fullstack developer trend, we love js too much, we have good workflow. now in react, too much noise, and ppl dont care good small pattern.
@austincodes
@austincodes 14 дней назад
I basically do this but with TRPC actions because I like to make all my DB calls from a router still 😊
@samislam2746
@samislam2746 16 дней назад
Who said that you can know the type returned by react query? you can pass a generic argument and it will use that as the fetched resource type on the data prop.
@jd_27
@jd_27 16 дней назад
Looks awesome
@skyhigheagleer6
@skyhigheagleer6 16 дней назад
Dislike the naming conventions, mutate != GET requests. The destructuring renaming adds mental overload for no reason. Using API routes is still OG in enterprise level apps imo
@t4styycs
@t4styycs 15 дней назад
SWR > react-query 😊
@kearfy
@kearfy 16 дней назад
react-query is basically react-async :P
Далее
It's Time To Talk About This Tailwind Plugin
7:26
Просмотров 4,4 тыс.
Learn TypeScript Generics In 13 Minutes
12:52
Просмотров 210 тыс.
How is it possible? 🫢😱 #tiktok #elsarca
00:13
Просмотров 2,2 млн
Khabib came to check on Poirier 👀 #UFC302
00:25
Просмотров 377 тыс.
REALLY LOVES CHIPS
00:19
Просмотров 1,9 млн
A flexbox trick to improve text wrapping
5:02
Просмотров 148 тыс.
BEST way to handle ICONS in your VITE APPS!
10:21
Просмотров 5 тыс.
My Favorite Update in a Long Time
10:08
Просмотров 30 тыс.
“Act On Press” - John Carmack's Hot Take On UI
7:54
Next js 15 is Here… New Changes Again?!
8:13
Просмотров 89 тыс.
Why Don't We Have A Laravel For JavaScript?
12:36
Просмотров 72 тыс.
Hands on with the Vercel AI SDK 3.1
13:04
Просмотров 22 тыс.
Плохие и хорошие видеокарты
1:00
Pratik Cat6 kablo soyma
0:15
Просмотров 8 млн