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

155
Views
Is there a way to pass an imported component through a function?

I'm using a library called SlidingPane, and each pane has the exact same styles, just different content depending on the page. So I want to put it into a separate page, and get the content through an argument:

export default function CustomSlidingPane(content){
    <SlidingPane
        className="slidingPanel"
        isOpen={state.isPaneOpen}
        onRequestClose={() => {
            setState({ isPaneOpen: false });
        }}
        >
        <Container>
            {content}
        </Container>
    </SlidingPane>
}

All of the content is in separate .js pages that kind of look like this:

export default function One() {
    return (
        <h1>Hello</h1>
    );
}

So what I'm trying to do is pass one of the content functions through to the CustomSlidingPane like this:

import One from './One';
import CustomSlidingPane from './CustomSlidingPane';

export default function Main(){
    <Container>
        <CustomSlidingPane content={<One/>}>
    </Container>
}

Every thing I've tried always ends up in content being undefined. Is there any proper way to do this / is this even possible?

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

0

A few things:

  1. It looks like you mighthave forgotten a return in CustomSlidingPane
  2. You need to destructure content from the props

Try this

export default function CustomSlidingPane({content}){
    return (
        <SlidingPane
        className="slidingPanel"
        isOpen={state.isPaneOpen}
        onRequestClose={() => {
            setState({ isPaneOpen: false });
        }}
        >
        <Container>
            {content}
        </Container>
    </SlidingPane>
    )
}

Also, this pattern might be supported better with the children prop.

about 4 years ago · Juan Pablo Isaza Report

0

You will need to use children prop here. I am adding an example with a simple div element.

export default function CustomSlidingPane(props) {
  return <div>{props.children}</div>;
}

Content will be same as you defined in your example:

export default function One() {
  return <h1>Hello</h1>;
}

This is how you can pass the content to your slidingPlane component:

export default function Main() {
  return (
    <div>
      <CustomSlidingPane>
        <One />
      </CustomSlidingPane>
    </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!