Craig P H
Craig P H

Reputation: 141

Next.js React app not showing custom component content

I am new to react and I am currently trying out some basic example. I have just created a linked index page and an about page. I then created a custom App component which should display everything in the container, instead it is just showing the home/about linked buttons and 'Hello next.js' text (it is not showing ('On every Page'). See page layout below

On every page *** this is not showing Home page button | About page button Hello next.js

Can anyone see any errors? I have tried searching but I still can not see where I am going wrong

// _app.js
import App, {Container} from 'next/app';

//define the custome App - a class which extends the 
default App
class myApp extends App {
return() {
    //compent will be the page content
    // e.g. index or about
    const {Component, pageProps} = this.props;

    return (
        //container contains page content
        <Container>
            {/* Content which will be shared */}
            <p>On every Page</p>
            {/* Component is page e.g. index or about 
*/}
            <Component {...pageProd}/>
        </Container>

    );
}
}
export default myApp;


//index.js
import Link from 'next/link'

// Pass this content as 'props' to child components
const Index = props => (
  <div>
<Link href="/index">
    <button>Home page</button>
</Link>
<Link href="/about">
    <button>About page</button>
</Link>


<p>Hello Next.js</p>
</div>
 )

export default Index


// about.js
import Link from 'next/link'

// Pass this content as 'props' tp child components
const About = props => (
<div>
<Link href="/">
    <button>Home page</button>
</Link>
<Link href="/about">
    <button>About page</button>
</Link>


<p>Hello Next.js</p>
</div>
)

export default About

Upvotes: 0

Views: 5165

Answers (2)

Rashmi Abbigeri
Rashmi Abbigeri

Reputation: 185

I had a similar problem, My issue was with cache , try this

rm -rf node_modules/ && rm -rf package-lock.json && npm install && npm run build:tailwind && npm run dev

Upvotes: 1

Alex
Alex

Reputation: 2146

yes.. first one is return instead of render

Upvotes: 1

Related Questions