L
L
lookingfor22021-02-23 20:30:08
JavaScript
lookingfor2, 2021-02-23 20:30:08

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

1 answer(s)
V
Valery, 2021-02-24
@lookingfor2

The only thing that comes to mind is that you are trying to call it from outside the page component

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question