Implementing Infinite Scroll in Next.js Using Server Actions

Поділитися
Вставка
  • Опубліковано 12 вер 2024

КОМЕНТАРІ • 4

  • @MartinRojas
    @MartinRojas 3 місяці тому +3

    this is not server actions. You are still calling the third Party REST API from the client components. If this was a true server actions then the network tab would show traffic to localhost not the third-party API.

    • @alias-wh1et
      @alias-wh1et 3 місяці тому +2

      I sorta agree.
      `getPosts` is called from the server when called from the server component `Home` in `src/app/page.tsx`, but is called from a client component as @MartinRojas mentioned when the "load more" button is clicked.
      Luckily, `getPosts` can be turned into a server action simply by adding 'use server' at the top of the `get-posts.ts` file. Then, `getPosts` would be called from the server even when called by a client component. (You can confirm by console-logging and looking at where the logs appear.)

  • @pelumini
    @pelumini 3 місяці тому

    Excellent! Straight to the point!

  • @mrbjjackson
    @mrbjjackson 15 днів тому

    When I try this I get an error that tells me: async/await is not yet supported in Client Components, only Server Components. Any ideas what I might have done differently to you?