Answer the question
In order to leave comments, you need to log in
Why is getServerSideProps not working?
If I make a preliminary request through getInitialProps, I receive data from the request and can pass it to the component, but
getServerSideProps does not work, I do it like in the docks, why doesn't it work?
import React, {useEffect} from "react";
import {apiGetApplication} from "../../src/services/Api";
import {withIronSession} from "next-iron-session";
function ProfileCom({user}) {
useEffect(() => {
apiGetApplication().then(r => console.log(r.data, "front"));
}, []);
console.log(user, "back");
return (
<section className="offer-accepted__wrapper">
<p>
{JSON.stringify(user)}
</p>
</section>
);
};
// ProfileCom.getInitialProps = async () => {
// const options = {
// method: "GET",
// headers: {
// "Content-Type": "application/json",
// "Accept": "application/json"
// }
// };
//
//
// // const response = await fetch("http://rc.webdb.dengisrazy.ru/ds/v1/applications", options)
// const response = await fetch('https://jsonplaceholder.typicode.com/users/1')
// const user = await response.json()
// console.log(response)
//
// return {
// user
}
// };
export async function getServerSideProps() {
const response = await fetch("https://jsonplaceholder.typicode.com/users/1");
const user = await response.json();
console.log(response);
return {props: {user}};
}
export default ProfileCom;
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question