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

191
Views
React/NextJS passing both children and other arguments to component

I'm using NextJS with a global PageLayout wrapper for all of my pages that sets the head and creates the wrapping divs for the page. However I am now trying to set a custom title tag for each page, which requires me to pass an argument to the PageLayout component with the page title I want to set. However when trying to pass both the PageLayout children and the page_title argument - the page_title property does not get passed in.

Here is what I have for the PageLayout component:

import Head from 'next/head'
import styles from "../../../styles/layout/PageLayout.module.scss"

const PageLayout = ({children, page_title}) => {
    console.log(`-------------------------------------------------------`)
    console.log(`Page Title: ${page_title}`)
    console.log('PAGE Children (NEXT LINE):')
    console.log(children)

    return (
        <div className={styles.container}>
            <Head>
                <title>{page_title}</title>
                <meta name="description" content="JWS Fine Art" />
                <link rel="icon" href="/JWS_ICON.png" />
                <link rel="preconnect" href="https://fonts.gstatic.com"/>
                <link href="https://fonts.googleapis.com/css2?family=Alegreya+Sans+SC:wght@300&family=Lato:wght@300&display=swap" rel="stylesheet"/>

            </Head>
            <main className={styles.main}>
                {children}
            </main>
        </div>
    )
}

export default PageLayout;

And here is an example of how I am passing in the page_title and children for one of my pages:

  return (
    <PageLayout page_title={"Orders"}>
      <div className={styles.main_container}>
        <div className={styles.main_body}>
          <h2 className={styles.module_title}>Order Management:</h2>
          {page_jsx}
        </div>
      </div>
    </PageLayout>
  )

And when I try to access that page, I see the following console output from the PageLayout logging: enter image description here

This all being said, I'm wondering if it is just not possible to pass both children and other arguments? I haven't been able to find any info on this issue online, and no method I have tried has worked, so am coming here. Would greatly appreciate any input anyone might have!

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Issue ended up being due to attempting to use "title" as a var name which seems to be a global variable name that can't be used - and also due to me failing to update both the mobile and desktop JSX for the page.

The functionality does work as expected, and you can pass both children and additional props. Thanks to @PrinceAgrawal for making me check my work properly :P

For a working example of this functionality, you can view this example repo: https://github.com/tsmith165/page_layout_example

about 4 years ago · Santiago Trujillo 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!