Okay, so here is my problem. I am getting props via getserversideprops, and I have tried multiple fixes but I can not get it to display. Here is the code:
import React, { Component } from 'react';
import rpstyle from '/styles/home/recentPosts.module.css'
export default class RecentPosts extends Component {
constructor() {
super()
this.state = { posts: this.props.posts }
}
static async getServerSideProps() {
const res = await fetch('http://localhost:5000/search/recentposts')
const json = await res.json()
return { posts : json }
}
viewAllButton(){
if(this.props.viewAll != false){
return (
<div className={rpstyle.viewAll}>
<a href='#'>View All Posts</a>
</div>
)
} else {
return null
}
}
render() {
return (
<div className={rpstyle.container}>
<hr />
<h1>Recent Posts</h1>
{console.log(this.props.posts)}
{this.viewAllButton()}
</div>
)
}
}
For some reason I can not find a good guide for class-based components and this method. If someone has any ideas on making this not display undefined
please let me know!