Next.js Discord

Discord Forum

How to do this in Next 13/14 (getServerSideProps deprecated)

Unanswered
Black Vulture posted this in #help-forum
Open in Discord
Black VultureOP
I want to use getServerSideProps and doesn't work because in new versions of Next.js is not allowed.
How can I archive this?

function Login({ query }) {
    const { error } = query;
    useEffect(() => {
        console.log('API URL IS:', process.env.NEXT_PUBLIC_API_URL);
        console.log(process.env.NODE_ENV);
        if (error) {
            toast.error(error);
        }
        router.replace(
            {
                query: {},
            },
            undefined,
            { shallow: true }
        );
    }, []);
function Login({ query }) {
/// ...
}
export async function getServerSideProps(context) {
    const { query, params } = context;

    return {
        props: {
            query,
        },
    };
}

3 Replies

Black VultureOP
I don't get it
getServerSideProps has been replaced by async/await server components.
Simply fetch your data directly inside your server component.