Thank you very much! I will try to use it in my project. But there I need to sort and filter ALL items. In this tutorial beer items placed in two different components. UPD. Passed initial served "beers" into "load-more" and got all items in one component. Also we don't need "experimental" for ServerActions in next-config anymore
great video, thanks ! On my side I did not need to separate the initial view with a distinct component to load more. From page.tsx I pass a prop with initial data to a single child client component, which can then modify the initial data state with more data through a server action
there was no need to mark the Beers component as client, but the LoadMore. 2: using the serverAction in a clientComponent makes no longer a server action. that means your sensitive data will be sent over the client http request.
I came up with a similar approach and wonder if it's a good practice to use server actions for actual get request. Docs say that they are supposed to be only for mutations, so I wonder if I should just use react query or something
Yes it would. Thats why I made a new video about "virtual lists". I would use that over this any day. This would be okay for upto a maximum of 1000 items and not more
`src/actions / fetch-products.ts` this file flag by `use server` but called by client side in load more. Can i put secret code or key in this file such as database password.
It was awesome, but what if use apollo client + infinite scroll?! I handle to fetch first page on server, then pass it to client component to render and call fetchMore ... but there is some problem, for example when i want to pass query as search, there is problem on render the current data !!
Technically you only need to ensure that your server actions return the data you are asking for. If you move away from this page to another page or url then this will not work as you need to somehow persist the old data on client-side. If you are facing problems then I would recommend you to do it entirely using client-components!
@@raj_talks_tech thanks for your message, Actually i think its impossible to use server actions, because fetching data on server and client is not the same in nextjs 13, because of that i didnt use server actions, for first page and when url changed(to fetch another first page based on the search query) i fetch on server , then pass it to client component ... actually part of it should be on client component, i think the logic is ok, but result no :)
Thanks man I had to implement an infinite scroll like this for my internship. That was very helpful.
Thank you very much! I will try to use it in my project. But there I need to sort and filter ALL items. In this tutorial beer items placed in two different components.
UPD. Passed initial served "beers" into "load-more" and got all items in one component. Also we don't need "experimental" for ServerActions in next-config anymore
I am making another video where I have filtering for entire list.
The project is already live you can check it out here gitposter.dev
Cool, straight to the point
Love this man! It’s exactly what I needed
Good job! Thanks a lot. You help me with my blog experiments
great video, thanks !
On my side I did not need to separate the initial view with a distinct component to load more.
From page.tsx I pass a prop with initial data to a single child client component, which can then modify the initial data state with more data through a server action
Then you need to watch my latest video, I have used React-virtuoso to do something similar ruclips.net/video/ocWc_FFc5jE/видео.html
Thank you so much for this useful and practical tutorial 🙏
Thanks for the feedback!
there was no need to mark the Beers component as client, but the LoadMore.
2: using the serverAction in a clientComponent makes no longer a server action. that means your sensitive data will be sent over the client http request.
Agreed the first item could have been a Server Component. 2nd point is new to me, thanks for the update !
wanted to see the api route where you query the data for inifinite scrolling...
@@anubhavnegi4230 Just checkout the code i. the description
How are you able to use async in a client component? I always get an error when I try this in NextJS
Thank you very much for this tutorial was very helpful
I came up with a similar approach and wonder if it's a good practice to use server actions for actual get request. Docs say that they are supposed to be only for mutations, so I wonder if I should just use react query or something
Yeah not a great practice. I will just use a virtualized list library like React-virtuoso and keep the data in a paginated API
can all endpoint support those stuff of perpage and page?
No. Your APIs need to be paginated. Meaning you need to specifically get that information from DB.
how can i add the item number in this infinite scroll
Hi
Thanks for your wonderfull toturial
How would be the inverse infinite scroll?
That would be slightly complicated with this approach. You can check out React-Virtuoso Library
won't it take a lot of memory if user just continues to scroll for a long time?
Yes it would. Thats why I made a new video about "virtual lists".
I would use that over this any day. This would be okay for upto a maximum of 1000 items and not more
`src/actions / fetch-products.ts`
this file flag by `use server` but called by client side in load more.
Can i put secret code or key in this file such as database password.
Usually not a problem. If u put something secret then I would recommend adding an extra layer of protection and use
import "server-only"
package
It was awesome, but what if use apollo client + infinite scroll?!
I handle to fetch first page on server, then pass it to client component to render and call fetchMore ... but there is some problem, for example when i want to pass query as search, there is problem on render the current data !!
Technically you only need to ensure that your server actions return the data you are asking for.
If you move away from this page to another page or url then this will not work as you need to somehow persist the old data on client-side.
If you are facing problems then I would recommend you to do it entirely using client-components!
@@raj_talks_tech thanks for your message,
Actually i think its impossible to use server actions, because fetching data on server and client is not the same in nextjs 13, because of that i didnt use server actions, for first page and when url changed(to fetch another first page based on the search query) i fetch on server , then pass it to client component ... actually part of it should be on client component, i think the logic is ok, but result no :)
Ah yes. Its a combination of server actions, RSCs and client components. Did you take a look at the code attached ?
hi, can you do this with Redux Toolkit?
thanks you 💯
I thought you weren't allowed to call async functions from client components?
You can call server actions from client-components.
Спасибо за ссылку на исходный код )
thanks a lot
thanks
it still has bugs
Hi. Can you post your question on Discord ?