I want to fetch data according to id. I have the id in my URL. So I need to get that id from the URL using useRouter. But when I call useRouter inside getServerSideProps for fetching data on the server side, it gives me this error: Invalid hook call. Hooks can only be called inside of the body of a function component.
Here is my code:
import React from 'react';
import { useRouter } from 'next/router';
const singleProject = (props) => {
return (
<div>
<h1>This is project Detail</h1>
</div>
);
};
export const getServerSideProps = async () => {
const router = useRouter();
const id = router.params;
console.log(id)
// const data = axios.get(`http://localhost:5000/project/${}`)
// return {
// props: {
// }
// }
}
export default singleProject;