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

84
Views
Use React children with another name

Is it possible to set a name for children in react for better code readability?
I want something like this:

default function LinksBar({ links = children }) {
    return (
        <div>
            {links} {/* instead of {children} */}
        </div>
    )
};

I know I can pass them in props, but I don't want to do it this way (just because of personal preference).

I don't want this:

<LinksBar links={<><Link href="1" /><Link href="2" /><>} />

I want this:

<LinksBar>
    <Link href="1" />
    <Link href="2" />
<LinksBar/>
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

You can alias it, although React speaking, it's less readable, in my opinion:

function LinksBar({ children: links })

about 4 years ago · Juan Pablo Isaza Report

0

function LinksBar({ links = children }) defines a parameter destructuring default, not destructuring renaming; it expects a links property and, if it's not found or has the value undefined, tries to default it to a children in-scope variable (presumably failing because there isn't one).

For renaming destructuring syntax, you want {children: links} instead:

default function LinksBar({children: links}) {
    return (
        <div>
            {links}
        </div>
    )
}
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!