Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

148
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda