Why am I consistently receiving undefined results when attempting to retrieve all posts from my backend? What could be causing this issue?
import { AppContext } from '@/helpers/Helpers'
import axios from 'axios'
import { GetStaticProps} from 'next'
import React, {useContext} from 'react'
import Tweet from './Tweet'
import { TweetsContainer } from './Tweets.styled'
export interface IAppProps {
}
export default function Tweets(props: any, { allPosts }: any) {
console.log(allPosts);
return (
<div>
<TweetsContainer>
<div>
</div>
</TweetsContainer>
</div>
);
}
export const getStaticProps: GetStaticProps = async () => {
const res = await axios.get(`http://localhost:7000/api/tweets`)
const data = res.data
return {
props: { allPosts: data }
}
}
Is this the correct method for retrieving data from an API in Next.js using TypeScript?