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

147
Vistas
Destructure object to pass n parameters

I have a function that I use to update my UI

updateUser: async (userId, slug, avatar, coverImage) => {
    const payload = {
        ...(slug && {
            slug
        }),
        ...(description && {
            avatar
        }),
        ...(coverImage && {
            coverImage
        })
    };
    return result.user.mutationUpdate({
        variables: {
            payload,
            userId
        }
    });
},

The thing is that this function is called in different placed in the UI, some of these places are to update the avatar only, or the user slug and so on. This has led to multiple functions on the UI where we do this

const handleUserCoverUpdate = useCallback(async (userId, coverImage) => {
    try {
        await user.updateChannel(userId, null, null, coverImage);
    } catch {
        //
    }
}, []);

const handleUserSlugUpdate = useCallback(async (userId, slug) => {
    try {
        await user.updateChannel(userId, slug, null, null);
    } catch {
        //
    }
}, []);

Meaning we pass parameters as whatever we need and the others as null, I feel this is getting a bit out of hand, would a better way be to pass a payload object and destructure it to get what is being send? If so how would that look with my current implementation, or is there a better way?

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