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

96
Views
Use Dynamic Wrapper for children React

I want to use a component passed from the props to wrap children, if defined.


interface ExampleProps {
  wrapper: JSX.Element;
}

function Example({ wrapper }: ExampleProps) {
  return (
    // Wrap this with `wrapper`, only if it is defined, else don't wrap.
    <Child></Child>
  )
}

How can this we be done?

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

0

You can do this way

function Example({ wrapper }) {
  if(wrapper) {
    const Wrapper = wrapper //to make it alike component
    return <Wrapper><Child></Child></Wrapper>
  }
  return (
    <Child></Child>
  )
}
about 4 years ago · Juan Pablo Isaza Report

0

Try:

function Example({ wrapper, children }) {
  const Wrapper = wrapper || React.Fragment; // custom components should start with capital letter
  return (
    <Wrapper>
     {children}
    </Wrapper>
  )
}
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!