SWR mutate() function in NEXTJS not fetching new data from endpoint in production environment #2715
-
In a NEWXTJS project, I'm using the SWR library to fetch an array of objects from a MongoDB database. The objects in the array are rendered in a table that is editable, meaning the user can modify a cell, and then its value is updated in the MongoDB database. To reflect the changes, I'm using the mutate() function after saving data to database. What could be the problem? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Finally, I found the issue: according to the NEXTJS 13 documentation, "Route Handlers are statically evaluated by default when using the GET method with the Response object," and later on, "Route handlers are evaluated dynamically when: Using the Request object with the GET method," among others. Therefore, keeping in mind this last premise of NEXTJS 13, I solved the problem with a simple change to the API using the Request object. Attached is the change in the API at backend. ` import { EstadoAdministrativo } from '@/models/estados'; export async function GET(request) {
} ` |
Beta Was this translation helpful? Give feedback.
Finally, I found the issue: according to the NEXTJS 13 documentation, "Route Handlers are statically evaluated by default when using the GET method with the Response object," and later on, "Route handlers are evaluated dynamically when: Using the Request object with the GET method," among others. Therefore, keeping in mind this last premise of NEXTJS 13, I solved the problem with a simple change to the API using the Request object. Attached is the change in the API at backend.
`
const mongoose = require('mongoose');
import { NextResponse } from 'next/server'
import { EstadoAdministrativo } from '@/models/estados';
//import { NextResponse } from 'next/server'
export async function GET(requ…