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

127
Views
Is there a way to destructure with spreader?

Here were the props I originally tried to pass through to a component:

const allprops = {
    mainprops:{mainprops}, // object
    pageid:{pageId}, // variable
    setpageid:{setPageId}, // state function
    makerefresh:{makeRefresh} // state function
}

<Navbar allprops={allprops} />

I quickly realized I created a monster -- some nested object:

{mainprops: {…}, pageid: {…}, setpageid: {…}, makerefresh: {…}}

 mainprops: {mainprops: {…}}

after breaking my head, I came up with this:

const Navbar = (props) => {
  const {allprops} = props;

  const {mainprops, ...userprops} = allprops
  const {mainprops:{} = {}} = mainprops;
  const {userprops:{} = {}} = userprops;

is there a way to turn this into a one liner? Or a loop or something faster/shorter?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are unnecessarily nesting your prop values inside an additional object. This:

const allprops = {
    mainprops:{mainprops}, // object
    pageid:{pageId}, // variable
    setpageid:{setPageId}, // state function
    makerefresh:{makeRefresh} // state function
}

can be made much more concise and easy to work with by changing it to:

const allprops = {
    mainprops,
    pageId,
    setPageId,
    makeRefresh
};

and by spreading that:

<Navbar {...allprops} />

And then in your child component, all you need is:

const Navbar = ({ mainprops, pageId, setPageId, makeRefresh }) => {
  // proceed to use mainprops, pageId, setPageId, makeRefresh
about 4 years ago · Juan Pablo Isaza Report
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!