Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

394
Vistas
How to mutate in SWR with query parameters such page after success patch request?
onSubmit={async (values, actions) => {
        const { birthdate, ...userData } = values;
        let formattedBirthDate = formatDate(birthdate);
        const updateUserUrl = `/api/users/update/${id}`;

        try {
          // send a request to the API to update the source
          const res = await api.patch(
            updateUserUrl,
            {
              ...userData,
              birthdate: formattedBirthDate,
            },
            { headers: { "Auth-Token": authToken } }
          );

          if (res && res.data) {
            mutate('api/users?page=1&limit=10',{ ...user, userData, birthdate: formattedBirthDate });
            router.replace("/admin?page=1&limit=10");
            toast.success("Updated successfully");
          }
        } catch (error) {
          if (error.response) {
            // The request was made and the server responded with a status code
            // that falls out of the range of 2xx
            toast.error(error.response.data.message);
            console.log("Error response data: ", error.response.data);
            console.log("Error response status: ", error.response.status);
            console.log(
              "Error response headers: ,",
              error.response.headers
            );
          } else {
            console.log("Error entity error: ", error.message);
            toast.error(error.message);
          }
        }

I am trying to mutate the table data to have an updated data but it won't work if the mutate URL is not correct. If the current data fetch is from page 2, then the mutate URL will be api/users?page=2&limit=10. How can I know if the current data is from page =2?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda