0

Data is not fetching when I am sending a request to get data by nextjs nature.But when I am calling getServerSideProps it returns data.

 export const getServerSideProps = async()=>{
        const res = await fetch(`http://localhost:5000/api/events`)
        const data = await res.json()
        console.log(data)
    
        return {props:{events:data}}
    }
    
    const EventList = ({events}) => {
        //const events= getServerSideProps()
        console.log(events)
    
        return (
            <div>
                <h3>List</h3>
            </div>
        );
    };
    
    export default EventList;
Md.Shakil Shaikh
  • 347
  • 4
  • 11
  • I want to catch events as props. but when I am printing events it shows undefined. – Md.Shakil Shaikh Jun 03 '22 at 18:24
  • `getServerSideProps` only works in page components, it won't work in regular components. See [NEXTJS: getServerSideProps not working into components](https://stackoverflow.com/questions/64136025/nextjs-getserversideprops-not-working-into-components). – juliomalves Jun 04 '22 at 10:22

0 Answers0