Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I conditionally send props depending on parent element?

I have a component called ListLayout which is a child component for two parent components. I want to pass props based on whichever page is being rendered. Is it possible?

The ListLayout component is as follows;

export default function ListLayout(props) {
    return (
    <div>
    <TabNavigation (conditionally accept here based on page being rendered) />
    </div>
}

Two parent components send props to ListLayout.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can do something like

export default function ListLayout(props) {
  return (
    <div>
      <TabNavigation pageData={props.pageOne ? 'send page one' : 'send page two'} />
    </div>
  )
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading