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

107
Views
How to pass props to inherited component in next.js

I have the following index.js page, that uses a layout component:

import Layout from "../components/layout";

export default function Home({posts}) {
  console.log(posts)

  return (
      <Layout posts={posts}>
        <div className="showmore" data-total="total">
              test
          
        </div>

      </Layout>
  )
}

export async function getServerSideProps() {
    const res = await fetch('http://gsr2.localhost.xip.io/api/news')
    const posts = await res.json()

    return {
        props: {
            posts,
        },
    }
}

How do I get the posts in the layout, to use in another component there?

This is my layout, but I only get the children and not anything else.


export default function Layout({children, props}) {
    console.log(children, props);
    return (
        <>
            <Head/>
            <main>{children}</main>
            <News>{props}</News
            <Footer/>
        </>
    )
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

There is a misunderstanding here, when you try to access children and props in you layout, you are trying to get a property props that would have passed to the component.

Instead you should do

({ children, posts })

There you should be able to access to posts.

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!