2024-08-29
3726
#nextjs
Peter Ekene Eze
183861
Aug 29, 2024 â‹… 13 min read

Diving into Server Actions in Next.js 14

Peter Ekene Eze Learn, Apply, Share

Recent posts:

Leaflet Adoption Guide: Overview, Examples, And Alternatives

Leaflet adoption guide: Overview, examples, and alternatives

Leaflet is a handy, lightweight, performant JavaScript library for creating responsive and interactive maps for the web.

Joseph Mawa
Sep 19, 2024 â‹… 11 min read
JavaScript logo with glowing lights, representing secure web authentication. Learn how JWT, OAuth, and Bearer tokens enhance modern authentication methods.

Understanding JWT, OAuth, and Bearer tokens

If you were to meet your friend in the street, straight away you would likely greet them and ask them […]

Lewis Cianci
Sep 19, 2024 â‹… 5 min read
An illustration of a hand holding a large hammer with a lightning bolt symbol. The background features a vibrant, gradient sky with shining stars. This image metaphorically represents the strength and flexibility of using Vike and vite-plugin-federation to build scalable micro-frontends. As discussed in the article, Vike allows for server-side rendering (SSR) and static-site generation (SSG), while vite-plugin-federation helps integrate shared components across different micro-frontend applications, enhancing the speed and modularity of modern web development frameworks like React, Vue, and Svelte

How to build scalable micro-frontends with Vike and Vite

Micro-frontends let you split a large web application into smaller, manageable pieces. It’s an approach inspired by the microservice architecture […]

Elijah Asaolu
Sep 18, 2024 â‹… 6 min read
Nitro: Revolutionizing Server-Side JavaScript

Nitro.js: Revolutionizing server-side JavaScript

Nitro.js is a solution in the server-side JavaScript landscape that offers features like universal deployment, auto-imports, and file-based routing.

Iniubong Obonguko
Sep 16, 2024 â‹… 11 min read
View all posts

2 Replies to "Diving into Server Actions in Next.js 14"

  1. So the main issue was that if we posted a new item into a list, we had to do the POST request and then pull data again with a GET to have the UI updated? And this was expensive because there are 2 requests for 1 action, basically, right?

    What we did was:
    – we had a layer for state management (i.e Redux)
    – a layer for API calls (middleware on client side)

    Upon a request, we updated UI optimistically or pessimistically, depending on what the team wanted.

    So, when someone does a POST request, it calls the middleware API, We await the status code, if it’s 200, we update the UI (redux state) and this way, we achieve consistency between server and client’s UI in 1 request, not 2. Which means only 1 server is needed (some S3 bucket for the react site files) and 1 action needed (like the pessimistically update mentioned above). No need for having a second server running the server-side components, no need to trigger a GETall after a POST to see the updated UI. Nothing. Just a well structured and organized application. And it still adheres to separation of concerns since on the backend I run edge functions for the updates etc. It’s just more things on the client. And I am totally fine with SSG because yes, first load is larger but then everything else is a breeze, not requiring calls to a server. But yeah, I guess anything goes nowadays.

Leave a Reply