Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!